Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-10-05 17:27:33 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-05 17:27:33 +0300
commite45804a3bb753006b6aeeef78327359fc724633c (patch)
tree1cc7e4415ae1b614c37d7b4a41fe4a0e91616876 /pose_library
parentbe3096daa0d6d8e1767efdb992653a336b6955cc (diff)
Pose Library: assign catalog when creating new pose asset
When creating a new pose asset (`POSELIB_OT_create_pose_asset`), assign it the the Asset Browser's active catalog. This ensures that the asset browser actually shows the newly created catalog. When there is no asset browser open, no catalog is assigned. When there are multiple asset browsers, the biggest one wins.
Diffstat (limited to 'pose_library')
-rw-r--r--pose_library/asset_browser.py7
-rw-r--r--pose_library/operators.py21
-rw-r--r--pose_library/pose_creation.py16
3 files changed, 37 insertions, 7 deletions
diff --git a/pose_library/asset_browser.py b/pose_library/asset_browser.py
index 8bedd968..036a271b 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 ff958a1d..9aa0333e 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 ac08b776..ffebd22d 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