Assets: add function to copy asset data to another ID #108547

Manually merged
Sybren A. Stüvel merged 7 commits from dr.sybren/blender:pr/asset-data-copy-to-id into main 2023-06-08 10:15:03 +02:00

7 Commits

Author SHA1 Message Date
Sybren A. Stüvel df0ec2b1c9 Disallow mark/clear asset by assigning to `asset_data` 2023-06-06 17:47:19 +02:00
Sybren A. Stüvel 84b42045c3 Merge remote-tracking branch 'origin/main' into pr/asset-data-copy-to-id 2023-06-05 18:00:26 +02:00
Sybren A. Stüvel a65f2437f8 Include comment to explain why you can clear the asset status by assigning None 2023-06-05 14:24:17 +02:00
Sybren A. Stüvel 3bceeda146 Slightly improve error message when assigning to non-assettable ID type 2023-06-05 14:23:23 +02:00
Sybren A. Stüvel 9e1bcc75e2 Allow 'clear asset' by assigning `None`
`id.asset_data = None` is now a way to clear the 'is asset' status. This
makes the assignment symmetrical, as `id.asset_data = some_other_data` can
also be used to actually mark the ID as asset.
2023-06-05 14:23:01 +02:00
Sybren A. Stüvel e7a21c6eda Review feedback
- Move functionality from RNA to ED
- Change from `src.asset_data.copy_to_id(dst)` function to direct
  assignment `dst.asset_data = src.asset_data`
2023-06-05 14:19:03 +02:00
Sybren A. Stüvel 2cd1343af0 Assets: add function to copy asset data to another ID
Add a function `some_id.asset_data.copy_to_id(other_id)` to copy the asset
data from one data-block to another. This is intended to be used in the
pose library, when updating a pose by simply creating a new asset and
having that replace the old one.

This is intentionally taking a copy, even though the above use case could
have sufficed with a higher-level 'move' function. By exposing this as a
copy, it can be used in a wider range of situations, from whatever Python
code wants to use it. This could include copying the asset data from the
active asset to all the other selected ones.

Any pre-existing asset data is freed before the copy is assigned. The
target ID doesn't have to be marked as asset yet for this function to work.
Note that using this function will make the destination ID an asset,
without going through the regular operator.
2023-06-02 16:07:41 +02:00