From df603f50e89952bbc2be536b6dc29f062a600b31 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 13 Jul 2023 13:50:23 -0400 Subject: [PATCH 1/9] Blender Kitsu: Add Property Group to Exclude Collections --- scripts-blender/addons/blender_kitsu/anim/ops.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index e4637380..1149a772 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -397,6 +397,15 @@ class KITSU_OT_unlink_collection_with_string(bpy.types.Operator): return {"FINISHED"} +class KITSU_PG_exclude_collection(bpy.types.PropertyGroup): + exclude: bpy.props.BoolProperty( + name="Exclude", + description="", + default=False, + override={"LIBRARY_OVERRIDABLE"}, + ) + + class KITSU_OT_anim_update_output_coll(bpy.types.Operator): bl_idname = "kitsu.anim_update_output_coll" bl_label = "Update Output Collection" @@ -474,14 +483,19 @@ classes = [ KITSU_OT_anim_update_output_coll, KITSU_OT_anim_enforce_naming_convention, KITSU_OT_unlink_collection_with_string, + KITSU_PG_exclude_collection, ] def register(): for cls in classes: bpy.utils.register_class(cls) + bpy.types.Collection.blender_kitsu_exclusions = bpy.props.PointerProperty( + type=KITSU_PG_exclude_collection + ) def unregister(): for cls in reversed(classes): bpy.utils.unregister_class(cls) + del bpy.types.Collection.blender_kitsu_exclusions -- 2.30.2 From 31f3ccb2886cb7269948d9064d1d9bd8a29b3dc4 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 13 Jul 2023 13:50:24 -0400 Subject: [PATCH 2/9] Blender Kitsu: re-structure anim_update_output_coll --- .../addons/blender_kitsu/anim/ops.py | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index 1149a772..7f9c8ecc 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -413,6 +413,15 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): bl_description = ( "Scans scene for any collections that are not yet in the output collection" ) + active_shot = None + output_coll_name = None + output_coll = None + asset_colls = NotImplementedError + + exclude_collections: bpy.props.BoolProperty( + name="Exclude Collections", + description="Exclude selectied collections from the 'anim.output' collection", + ) @classmethod def poll(cls, context: bpy.types.Context) -> bool: @@ -425,24 +434,18 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): return bool(active_shot and output_coll) - def execute(self, context: bpy.types.Context) -> Set[str]: - active_shot = cache.shot_active_get() - output_coll_name = opsdata.get_output_coll_name(active_shot) - output_coll = bpy.data.collections[output_coll_name] + def invoke(self, context, event): + self.active_shot = cache.shot_active_get() + self.output_coll_name = opsdata.get_output_coll_name(self.active_shot) + self.output_coll = bpy.data.collections[self.output_coll_name] + return context.window_manager.invoke_props_dialog(self, width=500) - # Clear Out Output Collection before Starting - for collection in output_coll.children: - output_coll.children.unlink(collection) - bpy.context.view_layer.update() - - asset_colls = opsdata.find_asset_collections_in_scene(context.scene) + def get_collections(self, context): + self.asset_colls = opsdata.find_asset_collections_in_scene(context.scene) missing: List[bpy.types.Collection] = [] - output_coll_childs = list(opsdata.traverse_collection_tree(output_coll)) # Check if all found asset colls are in output coll. - for coll in asset_colls: - if coll in output_coll_childs: - continue + for coll in self.asset_colls: missing.append(coll) # Only take parent colls. @@ -455,10 +458,26 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): if coll_comp in coll_childs: childs.append(coll_comp) - parents = [coll for coll in missing if coll not in childs] + return [coll for coll in missing if coll not in childs] + + def draw(self, context): + layout = self.layout + layout.prop(self, "exclude_collections") + if not self.exclude_collections: + return + parents = self.get_collections(context) + for col in parents: + layout.prop(col.blender_kitsu_exclusions, "exclude", text=col.name) + + def execute(self, context: bpy.types.Context) -> Set[str]: + # Clear Out Output Collection before Starting + for collection in self.output_coll.children: + self.output_coll.children.unlink(collection) + bpy.context.view_layer.update() + parents = self.get_collections(context) for coll in parents: - output_coll.children.link(coll) - logger.info("%s linked in %s", coll.name, output_coll.name) + self.output_coll.children.link(coll) + logger.info("%s linked in %s", coll.name, self.output_coll.name) # Ensure Camera Rig is Linked for coll in [col for col in bpy.data.collections]: @@ -466,11 +485,11 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): if ( coll.override_library.hierarchy_root.name == "CA-camera_rig" ): # TODO Fix this hack to be generic - output_coll.children.link(coll) + self.output_coll.children.link(coll) self.report( {"INFO"}, - f"Found Asset Collections: {len(asset_colls)} | Added to output collection: {len(parents)}", + f"Found Asset Collections: {len(self.asset_colls)} | Added to output collection: {len(parents)}", ) return {"FINISHED"} -- 2.30.2 From 62f4d00429e084faa1b4ef5d40ed2293a5342d59 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 13 Jul 2023 13:50:25 -0400 Subject: [PATCH 3/9] Blender Kitsu: Enforce Black Formatting --- .../addons/blender_kitsu/anim/ops.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index 7f9c8ecc..2d12dc16 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -109,16 +109,20 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator): ) wrong: List[Tuple[bpy.types.Action, str]] = [] created: List[bpy.types.Action] = [] - cleanup_empty_actions: bpy.props.BoolProperty(name="Delete Empty Action Data-Blocks", default=False, description="Remove any empty action data-blocks, actions that have 0 Fcurves/Keyframes") - + cleanup_empty_actions: bpy.props.BoolProperty( + name="Delete Empty Action Data-Blocks", + default=False, + description="Remove any empty action data-blocks, actions that have 0 Fcurves/Keyframes", + ) + # List of tuples that contains the action on index 0 with the wrong name # and the name it should have on index 1. @classmethod def poll(cls, context: bpy.types.Context) -> bool: return bool(cache.shot_active_get()) - - def get_action(self, action_name:str): + + def get_action(self, action_name: str): if bpy.data.actions.get(action_name): return bpy.data.actions.get(action_name) else: @@ -135,17 +139,17 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator): succeeded = [] removed = [] - if self.cleanup_empty_actions: for action in bpy.data.actions: - if len(action.fcurves) == 0 and action.use_fake_user and action.users == 1: + if ( + len(action.fcurves) == 0 + and action.use_fake_user + and action.users == 1 + ): removed.append(action.name) action.use_fake_user = False bpy.data.actions.remove(action) - - - for obj in [obj for obj in bpy.data.objects if obj.type == "ARMATURE"]: # Cerate Action if None Exists if obj.animation_data is None or obj.animation_data.action is None: @@ -185,8 +189,6 @@ class KITSU_OT_anim_check_action_names(bpy.types.Operator): report_str += f" | Rename Failed: {len(failed)}" if len(self.created) != 0: report_str += f" | Created Actions: {len(self.created)}" - - self.report( {report_state}, -- 2.30.2 From 1ef927d419ae6689e265a14b0d2b30a4cd38d8b2 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 13 Jul 2023 13:50:25 -0400 Subject: [PATCH 4/9] Blender Kitsu: Exclude Collections marked for Exclusion from Update Output Collection --- scripts-blender/addons/blender_kitsu/anim/ops.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index 2d12dc16..9d043b50 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -460,6 +460,7 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): if coll_comp in coll_childs: childs.append(coll_comp) + # TODO check why this only returns some collections after running operator once return [coll for coll in missing if coll not in childs] def draw(self, context): @@ -477,6 +478,10 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): self.output_coll.children.unlink(collection) bpy.context.view_layer.update() parents = self.get_collections(context) + if self.exclude_collections: + parents = [ + col for col in parents if not col.blender_kitsu_exclusions.exclude + ] for coll in parents: self.output_coll.children.link(coll) logger.info("%s linked in %s", coll.name, self.output_coll.name) -- 2.30.2 From 57d2d334a9a15c6cabfed6457ec7598504532988 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 13 Jul 2023 13:50:26 -0400 Subject: [PATCH 5/9] Blender Kitsu: Ensure all aval collections appear in exclusion list --- scripts-blender/addons/blender_kitsu/anim/ops.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index 9d043b50..0487734e 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -460,7 +460,6 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): if coll_comp in coll_childs: childs.append(coll_comp) - # TODO check why this only returns some collections after running operator once return [coll for coll in missing if coll not in childs] def draw(self, context): @@ -469,6 +468,9 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): if not self.exclude_collections: return parents = self.get_collections(context) + # Must display collections that already exist in output collection so user can exclude them + for col in self.output_coll.children: + parents.append(col) for col in parents: layout.prop(col.blender_kitsu_exclusions, "exclude", text=col.name) -- 2.30.2 From 35676a7614fb87abd0110008a634d5481674da32 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 13 Jul 2023 13:50:27 -0400 Subject: [PATCH 6/9] Blender Kitsu: Improve Exclude Collection UI --- scripts-blender/addons/blender_kitsu/anim/ops.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index 0487734e..f44095d0 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -471,8 +471,11 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): # Must display collections that already exist in output collection so user can exclude them for col in self.output_coll.children: parents.append(col) + box = layout.box() + box.label(text="Select Collection to Exclude", icon="OUTLINER_COLLECTION") + column = box.column(align=True) for col in parents: - layout.prop(col.blender_kitsu_exclusions, "exclude", text=col.name) + column.prop(col.blender_kitsu_exclusions, "exclude", text=col.name) def execute(self, context: bpy.types.Context) -> Set[str]: # Clear Out Output Collection before Starting -- 2.30.2 From 4997ab0a10f8f22b1fe0a2786d907b52c55faba5 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 13 Jul 2023 13:50:27 -0400 Subject: [PATCH 7/9] Blender Kitsu: Remove Optional Exclude Mode Property --- scripts-blender/addons/blender_kitsu/anim/ops.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index f44095d0..faf00db8 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -418,12 +418,7 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): active_shot = None output_coll_name = None output_coll = None - asset_colls = NotImplementedError - - exclude_collections: bpy.props.BoolProperty( - name="Exclude Collections", - description="Exclude selectied collections from the 'anim.output' collection", - ) + asset_colls = None @classmethod def poll(cls, context: bpy.types.Context) -> bool: @@ -463,14 +458,11 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): return [coll for coll in missing if coll not in childs] def draw(self, context): - layout = self.layout - layout.prop(self, "exclude_collections") - if not self.exclude_collections: - return parents = self.get_collections(context) # Must display collections that already exist in output collection so user can exclude them for col in self.output_coll.children: parents.append(col) + layout = self.layout box = layout.box() box.label(text="Select Collection to Exclude", icon="OUTLINER_COLLECTION") column = box.column(align=True) -- 2.30.2 From f2d0cd744bdb80f54fd729e0338ab0b047e27385 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 13 Jul 2023 13:50:28 -0400 Subject: [PATCH 8/9] Blender Kitsu: Simplify Get Collections Function for Update Output Collection --- .../addons/blender_kitsu/anim/ops.py | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index faf00db8..c8b95651 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -439,23 +439,17 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): def get_collections(self, context): self.asset_colls = opsdata.find_asset_collections_in_scene(context.scene) - missing: List[bpy.types.Collection] = [] - - # Check if all found asset colls are in output coll. - for coll in self.asset_colls: - missing.append(coll) - # Only take parent colls. childs = [] - for i in range(len(missing)): - coll = missing[i] + for i in range(len(self.asset_colls)): + coll = self.asset_colls[i] coll_childs = list(opsdata.traverse_collection_tree(coll)) - for j in range(i + 1, len(missing)): - coll_comp = missing[j] + for j in range(i + 1, len(self.asset_colls)): + coll_comp = self.asset_colls[j] if coll_comp in coll_childs: childs.append(coll_comp) - return [coll for coll in missing if coll not in childs] + return [coll for coll in self.asset_colls if coll not in childs] def draw(self, context): parents = self.get_collections(context) @@ -475,10 +469,7 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): self.output_coll.children.unlink(collection) bpy.context.view_layer.update() parents = self.get_collections(context) - if self.exclude_collections: - parents = [ - col for col in parents if not col.blender_kitsu_exclusions.exclude - ] + parents = [col for col in parents if not col.blender_kitsu_exclusions.exclude] for coll in parents: self.output_coll.children.link(coll) logger.info("%s linked in %s", coll.name, self.output_coll.name) -- 2.30.2 From ef43ae466c60ad68ab5c6ae5ac658914a3995703 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Thu, 13 Jul 2023 13:50:29 -0400 Subject: [PATCH 9/9] Blender Kitsu: Improve Documentation and remove no-op code --- .../addons/blender_kitsu/anim/ops.py | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/anim/ops.py b/scripts-blender/addons/blender_kitsu/anim/ops.py index c8b95651..8a17e1b1 100644 --- a/scripts-blender/addons/blender_kitsu/anim/ops.py +++ b/scripts-blender/addons/blender_kitsu/anim/ops.py @@ -399,7 +399,7 @@ class KITSU_OT_unlink_collection_with_string(bpy.types.Operator): return {"FINISHED"} -class KITSU_PG_exclude_collection(bpy.types.PropertyGroup): +class KITSU_PG_anim_exclude_coll(bpy.types.PropertyGroup): exclude: bpy.props.BoolProperty( name="Exclude", description="", @@ -415,8 +415,6 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): bl_description = ( "Scans scene for any collections that are not yet in the output collection" ) - active_shot = None - output_coll_name = None output_coll = None asset_colls = None @@ -432,9 +430,9 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): return bool(active_shot and output_coll) def invoke(self, context, event): - self.active_shot = cache.shot_active_get() - self.output_coll_name = opsdata.get_output_coll_name(self.active_shot) - self.output_coll = bpy.data.collections[self.output_coll_name] + active_shot = cache.shot_active_get() + output_coll_name = opsdata.get_output_coll_name(active_shot) + self.output_coll = bpy.data.collections[output_coll_name] return context.window_manager.invoke_props_dialog(self, width=500) def get_collections(self, context): @@ -461,7 +459,7 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): box.label(text="Select Collection to Exclude", icon="OUTLINER_COLLECTION") column = box.column(align=True) for col in parents: - column.prop(col.blender_kitsu_exclusions, "exclude", text=col.name) + column.prop(col.anim_output, "exclude", text=col.name) def execute(self, context: bpy.types.Context) -> Set[str]: # Clear Out Output Collection before Starting @@ -469,7 +467,7 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator): self.output_coll.children.unlink(collection) bpy.context.view_layer.update() parents = self.get_collections(context) - parents = [col for col in parents if not col.blender_kitsu_exclusions.exclude] + parents = [col for col in parents if not col.anim_output.exclude] for coll in parents: self.output_coll.children.link(coll) logger.info("%s linked in %s", coll.name, self.output_coll.name) @@ -497,19 +495,19 @@ classes = [ KITSU_OT_anim_update_output_coll, KITSU_OT_anim_enforce_naming_convention, KITSU_OT_unlink_collection_with_string, - KITSU_PG_exclude_collection, + KITSU_PG_anim_exclude_coll, ] def register(): for cls in classes: bpy.utils.register_class(cls) - bpy.types.Collection.blender_kitsu_exclusions = bpy.props.PointerProperty( - type=KITSU_PG_exclude_collection + bpy.types.Collection.anim_output = bpy.props.PointerProperty( + type=KITSU_PG_anim_exclude_coll ) def unregister(): for cls in reversed(classes): bpy.utils.unregister_class(cls) - del bpy.types.Collection.blender_kitsu_exclusions + del bpy.types.Collection.anim_output -- 2.30.2