Assets: Remove (almost) all usages of asset handle in Python scripts
The asset handle type is supposed to be replaced by the asset representation type. It is designed for the asset system as opposed to the file browser backend. Withd421ebac5e,d04cd3f3e6andf6a6b27ac1, it can now do everything that is needed in Python to be a replacement. With this commit the asset handle type and the file handle type it uses is almost entirely replaced in Python files (only for the asset view template we require a collection property taking asset handles still, for internal reasons.) Part of #102877 and #108806.
This commit is contained in:
@@ -20,10 +20,10 @@ from bpy_extras.asset_utils import (
|
||||
class AssetBrowserMetadataOperator:
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
if not SpaceAssetInfo.is_asset_browser_poll(context) or not context.asset_file_handle:
|
||||
if not SpaceAssetInfo.is_asset_browser_poll(context) or not context.asset:
|
||||
return False
|
||||
|
||||
if not context.asset_file_handle.local_id:
|
||||
if not context.asset.local_id:
|
||||
Operator.poll_message_set(
|
||||
"Asset metadata from external asset libraries can't be "
|
||||
"edited, only assets stored in the current file can"
|
||||
@@ -58,13 +58,13 @@ class ASSET_OT_tag_remove(AssetBrowserMetadataOperator, Operator):
|
||||
if not super().poll(context):
|
||||
return False
|
||||
|
||||
active_asset_file = context.asset_file_handle
|
||||
asset_metadata = active_asset_file.asset_data
|
||||
active_asset = context.asset
|
||||
asset_metadata = active_asset.metadata
|
||||
return asset_metadata.active_tag in range(len(asset_metadata.tags))
|
||||
|
||||
def execute(self, context):
|
||||
active_asset_file = context.asset_file_handle
|
||||
asset_metadata = active_asset_file.asset_data
|
||||
active_asset = context.asset
|
||||
asset_metadata = active_asset.metadata
|
||||
tag = asset_metadata.tags[asset_metadata.active_tag]
|
||||
|
||||
asset_metadata.tags.remove(tag)
|
||||
@@ -84,24 +84,24 @@ class ASSET_OT_open_containing_blend_file(Operator):
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
asset_file_handle = getattr(context, "asset_file_handle", None)
|
||||
asset = getattr(context, "asset", None)
|
||||
|
||||
if not asset_file_handle:
|
||||
if not asset:
|
||||
cls.poll_message_set("No asset selected")
|
||||
return False
|
||||
if asset_file_handle.local_id:
|
||||
if asset.local_id:
|
||||
cls.poll_message_set("Selected asset is contained in the current file")
|
||||
return False
|
||||
return True
|
||||
|
||||
def execute(self, context):
|
||||
asset_file_handle = context.asset_file_handle
|
||||
asset = context.asset
|
||||
|
||||
if asset_file_handle.local_id:
|
||||
if asset.local_id:
|
||||
self.report({'WARNING'}, "This asset is stored in the current blend file")
|
||||
return {'CANCELLED'}
|
||||
|
||||
asset_lib_path = bpy.types.AssetHandle.get_full_library_path(asset_file_handle)
|
||||
asset_lib_path = asset.full_library_path
|
||||
self.open_in_new_blender(asset_lib_path)
|
||||
|
||||
wm = context.window_manager
|
||||
|
||||
@@ -709,58 +709,58 @@ class ASSETBROWSER_PT_metadata(asset_utils.AssetBrowserPanel, Panel):
|
||||
bl_options = {'HIDE_HEADER'}
|
||||
|
||||
@staticmethod
|
||||
def metadata_prop(layout, asset_data, propname):
|
||||
def metadata_prop(layout, asset_metadata, propname):
|
||||
"""
|
||||
Only display properties that are either set or can be modified (i.e. the
|
||||
asset is in the current file). Empty, non-editable fields are not really useful.
|
||||
"""
|
||||
if getattr(asset_data, propname) or not asset_data.is_property_readonly(propname):
|
||||
layout.prop(asset_data, propname)
|
||||
if getattr(asset_metadata, propname) or not asset_metadata.is_property_readonly(propname):
|
||||
layout.prop(asset_metadata, propname)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
wm = context.window_manager
|
||||
asset_file_handle = context.asset_file_handle
|
||||
asset = context.asset
|
||||
|
||||
if asset_file_handle is None:
|
||||
if asset is None:
|
||||
layout.label(text="No active asset", icon='INFO')
|
||||
return
|
||||
|
||||
prefs = context.preferences
|
||||
show_asset_debug_info = prefs.view.show_developer_ui and prefs.experimental.show_asset_debug_info
|
||||
is_local_asset = bool(asset_file_handle.local_id)
|
||||
is_local_asset = bool(asset.local_id)
|
||||
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False # No animation.
|
||||
|
||||
if is_local_asset:
|
||||
# If the active file is an ID, use its name directly so renaming is possible from right here.
|
||||
layout.prop(asset_file_handle.local_id, "name")
|
||||
layout.prop(asset.local_id, "name")
|
||||
|
||||
if show_asset_debug_info:
|
||||
col = layout.column(align=True)
|
||||
col.label(text="Asset Catalog:")
|
||||
col.prop(asset_file_handle.local_id.asset_data, "catalog_id", text="UUID")
|
||||
col.prop(asset_file_handle.local_id.asset_data, "catalog_simple_name", text="Simple Name")
|
||||
col.prop(asset.local_id.asset_data, "catalog_id", text="UUID")
|
||||
col.prop(asset.local_id.asset_data, "catalog_simple_name", text="Simple Name")
|
||||
else:
|
||||
layout.prop(asset_file_handle, "name")
|
||||
layout.prop(asset, "name")
|
||||
|
||||
if show_asset_debug_info:
|
||||
col = layout.column(align=True)
|
||||
col.enabled = False
|
||||
col.label(text="Asset Catalog:")
|
||||
col.prop(asset_file_handle.asset_data, "catalog_id", text="UUID")
|
||||
col.prop(asset_file_handle.asset_data, "catalog_simple_name", text="Simple Name")
|
||||
col.prop(asset.metadata, "catalog_id", text="UUID")
|
||||
col.prop(asset.metadata, "catalog_simple_name", text="Simple Name")
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.prop(wm, "asset_path_dummy", text="Source", icon='CURRENT_FILE' if is_local_asset else 'NONE')
|
||||
row.operator("asset.open_containing_blend_file", text="", icon='TOOL_SETTINGS')
|
||||
|
||||
asset_data = asset_file_handle.asset_data
|
||||
self.metadata_prop(layout, asset_data, "description")
|
||||
self.metadata_prop(layout, asset_data, "license")
|
||||
self.metadata_prop(layout, asset_data, "copyright")
|
||||
self.metadata_prop(layout, asset_data, "author")
|
||||
metadata = asset.metadata
|
||||
self.metadata_prop(layout, metadata, "description")
|
||||
self.metadata_prop(layout, metadata, "license")
|
||||
self.metadata_prop(layout, metadata, "copyright")
|
||||
self.metadata_prop(layout, metadata, "author")
|
||||
|
||||
|
||||
class ASSETBROWSER_PT_metadata_preview(asset_utils.AssetMetaDataPanel, Panel):
|
||||
@@ -877,14 +877,14 @@ classes = (
|
||||
|
||||
|
||||
def asset_path_str_get(_self):
|
||||
asset_file_handle = bpy.context.asset_file_handle
|
||||
if asset_file_handle is None:
|
||||
asset = bpy.context.asset
|
||||
if asset is None:
|
||||
return ""
|
||||
|
||||
if asset_file_handle.local_id:
|
||||
if asset.local_id:
|
||||
return "Current File"
|
||||
|
||||
return bpy.types.AssetHandle.get_full_library_path(asset_file_handle)
|
||||
return asset.full_library_path
|
||||
|
||||
|
||||
def register_props():
|
||||
|
||||
Reference in New Issue
Block a user