diff --git a/pose_library/asset_browser.py b/pose_library/asset_browser.py index 8bedd968259644dc0c2af8c7d17f81d8864183b4..036a271bf934bea9ea13902614a5f1785a57c5f8 100644 --- a/pose_library/asset_browser.py +++ b/pose_library/asset_browser.py @@ -68,9 +68,14 @@ def activate_asset( def active_catalog_id(asset_browser: bpy.types.Area) -> str: """Return the ID of the catalog shown in the asset browser.""" + return params(asset_browser).catalog_id + + +def params(asset_browser: bpy.types.Area) -> bpy.types.FileAssetSelectParams: + """Return the asset browser parameters given its Area.""" space_data = asset_browser.spaces[0] assert asset_utils.SpaceAssetInfo.is_asset_browser(space_data) - return space_data.params.catalog_id + return space_data.params def tag_redraw(screen: bpy.types.Screen) -> None: diff --git a/pose_library/operators.py b/pose_library/operators.py index ff958a1dc38d7998bb3b5f4eaa8967355dd49f84..9aa0333e76318507000fdc26414df1bff50aaf23 100644 --- a/pose_library/operators.py +++ b/pose_library/operators.py @@ -82,6 +82,23 @@ class POSELIB_OT_create_pose_asset(PoseAssetCreator, Operator): pose_name: StringProperty(name="Pose Name") # type: ignore activate_new_action: BoolProperty(name="Activate New Action", default=True) # type: ignore + + @classmethod + def poll(cls, context: Context) -> bool: + # Make sure that if there is an asset browser open, the artist can see the newly created pose asset. + asset_browse_area: Optional[bpy.types.Area] = asset_browser.area_from_context(context) + if not asset_browse_area: + # No asset browser is visible, so there also aren't any expectations + # that this asset will be visible. + return True + + asset_space_params = asset_browser.params(asset_browse_area) + if asset_space_params.asset_library_ref != 'LOCAL': + cls.poll_message_set("Asset Browser must be set to the Current File library") + return False + + return True + def execute(self, context: Context) -> Set[str]: pose_name = self.pose_name or context.object.name asset = pose_creation.create_pose_asset_from_context(context, pose_name) @@ -107,13 +124,13 @@ class POSELIB_OT_create_pose_asset(PoseAssetCreator, Operator): This makes it possible to immediately check & edit the created pose asset. """ - asset_browse_area: Optional[bpy.types.Area] = asset_browser.biggest_asset_browser_area(context.screen) + asset_browse_area: Optional[bpy.types.Area] = asset_browser.area_from_context(context) if not asset_browse_area: return # After creating an asset, the window manager has to process the # notifiers before editors should be manipulated. - pose_creation.assign_tags_from_asset_browser(asset, asset_browse_area) + pose_creation.assign_from_asset_browser(asset, asset_browse_area) # Pass deferred=True, because we just created a new asset that isn't # known to the Asset Browser space yet. That requires the processing of diff --git a/pose_library/pose_creation.py b/pose_library/pose_creation.py index ac08b776279516d60f594a2c8e275a9b9d4b91a5..ffebd22d8ee763f14b685c0078a32436d27eb23e 100644 --- a/pose_library/pose_creation.py +++ b/pose_library/pose_creation.py @@ -23,13 +23,15 @@ Pose Library - creation functions. import dataclasses import functools import re + from typing import Optional, FrozenSet, Set, Union, Iterable, cast if "functions" not in locals(): - from . import functions + from . import asset_browser, functions else: import importlib + asset_browser = importlib.reload(asset_browser) functions = importlib.reload(functions) import bpy @@ -432,6 +434,12 @@ def find_keyframe(fcurve: FCurve, frame: float) -> Optional[Keyframe]: return None -def assign_tags_from_asset_browser(asset: Action, asset_browser: bpy.types.Area) -> None: - # TODO(Sybren): implement - return +def assign_from_asset_browser(asset: Action, asset_browser_area: bpy.types.Area) -> None: + """Assign some things from the asset browser to the asset. + + This sets the current catalog ID, and in the future could include tags + from the active dynamic catalog, etc. + """ + + cat_id = asset_browser.active_catalog_id(asset_browser_area) + asset.asset_data.catalog_id = cat_id