Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_operators/assets.py
| Show All 21 Lines | |||||
| import bpy | import bpy | ||||
| from bpy.types import Operator | from bpy.types import Operator | ||||
| from bpy_extras.asset_utils import ( | from bpy_extras.asset_utils import ( | ||||
| SpaceAssetInfo, | SpaceAssetInfo, | ||||
| ) | ) | ||||
| class ASSET_OT_tag_add(Operator): | class AssetBrowserMetadataOperator: | ||||
| @classmethod | |||||
| def poll(cls, context): | |||||
| if not SpaceAssetInfo.is_asset_browser_poll(context) or not context.asset_file_handle: | |||||
| return False | |||||
| if not context.asset_file_handle.local_id: | |||||
| Operator.poll_message_set( | |||||
| "Asset metadata from external asset libraries can't be " | |||||
| "edited, only assets stored in the current file can" | |||||
sybren: The sentence is incomplete, "... only from the Current File asset library can" would be… | |||||
| ) | |||||
| return False | |||||
| return True | |||||
| class ASSET_OT_tag_add(AssetBrowserMetadataOperator, Operator): | |||||
| """Add a new keyword tag to the active asset""" | """Add a new keyword tag to the active asset""" | ||||
| bl_idname = "asset.tag_add" | bl_idname = "asset.tag_add" | ||||
| bl_label = "Add Asset Tag" | bl_label = "Add Asset Tag" | ||||
| bl_options = {'REGISTER', 'UNDO'} | bl_options = {'REGISTER', 'UNDO'} | ||||
| @classmethod | |||||
| def poll(cls, context): | |||||
| return SpaceAssetInfo.is_asset_browser_poll(context) and SpaceAssetInfo.get_active_asset(context) | |||||
| def execute(self, context): | def execute(self, context): | ||||
| active_asset = SpaceAssetInfo.get_active_asset(context) | active_asset = SpaceAssetInfo.get_active_asset(context) | ||||
| active_asset.tags.new("Unnamed Tag") | active_asset.tags.new("Unnamed Tag") | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class ASSET_OT_tag_remove(Operator): | class ASSET_OT_tag_remove(AssetBrowserMetadataOperator, Operator): | ||||
| """Remove an existing keyword tag from the active asset""" | """Remove an existing keyword tag from the active asset""" | ||||
| bl_idname = "asset.tag_remove" | bl_idname = "asset.tag_remove" | ||||
| bl_label = "Remove Asset Tag" | bl_label = "Remove Asset Tag" | ||||
| bl_options = {'REGISTER', 'UNDO'} | bl_options = {'REGISTER', 'UNDO'} | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| if not SpaceAssetInfo.is_asset_browser_poll(context): | if not super().poll(context): | ||||
Done Inline ActionsThis should be super().poll(context) instead. sybren: This should be `super().poll(context)` instead. | |||||
| return False | return False | ||||
| active_asset = SpaceAssetInfo.get_active_asset(context) | active_asset_file = context.asset_file_handle | ||||
| if not active_asset: | asset_metadata = active_asset_file.asset_data | ||||
| return False | return asset_metadata.active_tag in range(len(asset_metadata.tags)) | ||||
| return active_asset.active_tag in range(len(active_asset.tags)) | |||||
| def execute(self, context): | def execute(self, context): | ||||
| active_asset = SpaceAssetInfo.get_active_asset(context) | active_asset_file = context.asset_file_handle | ||||
| tag = active_asset.tags[active_asset.active_tag] | asset_metadata = active_asset_file.asset_data | ||||
| tag = asset_metadata.tags[asset_metadata.active_tag] | |||||
| active_asset.tags.remove(tag) | asset_metadata.tags.remove(tag) | ||||
| active_asset.active_tag -= 1 | asset_metadata.active_tag -= 1 | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class ASSET_OT_open_containing_blend_file(Operator): | class ASSET_OT_open_containing_blend_file(Operator): | ||||
| """Open the blend file that contains the active asset""" | """Open the blend file that contains the active asset""" | ||||
| bl_idname = "asset.open_containing_blend_file" | bl_idname = "asset.open_containing_blend_file" | ||||
| ▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines | |||||
The sentence is incomplete, "... only from the Current File asset library can" would be complete.
However, this may become obsolete soon. How about "... only assets stored in the current file can"? That way it's independent of the selected asset library.