From 2274f2be4b50c4409e5df151ad359afc6dac7d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 8 Jan 2024 14:34:00 +0100 Subject: [PATCH] Anim: fix Solo Bone Collection operator Fix the 'Show All' bone collection operator, by making it operate on all collections instead of just the roots. It also now ensures that all ancestors of the solo'ed collection are shown (otherwise it's the only visible one, but given that its parent is hidden, it's still not visible). This also fixes a related issue, where calling the operator without passing the `name` parameter would do nothing. Now it soloes the active bone collection. --- scripts/startup/bl_operators/anim.py | 34 +++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/scripts/startup/bl_operators/anim.py b/scripts/startup/bl_operators/anim.py index 309b88fadc9..9846b8e2010 100644 --- a/scripts/startup/bl_operators/anim.py +++ b/scripts/startup/bl_operators/anim.py @@ -525,9 +525,16 @@ class ARMATURE_OT_copy_bone_color_to_selected(Operator): class ARMATURE_OT_collection_solo_visibility(Operator): - """Hide all other bone collections and show the active one""" + """Hide all other bone collections and show the active one. + + Note that it is necessary to also show the ancestors of the active bone + collection in order to ensure its visibility. + """ bl_idname = "armature.collection_solo_visibility" bl_label = "Solo Visibility" + bl_description = "Hide all other bone collections and show the active one. " + \ + "Note that it is necessary to also show the ancestors of the active " + \ + "bone collection in order to ensure its visibility" bl_options = {'REGISTER', 'UNDO'} name: StringProperty(name='Bone Collection') @@ -538,8 +545,29 @@ class ARMATURE_OT_collection_solo_visibility(Operator): def execute(self, context): arm = context.object.data - for bcoll in arm.collections: - bcoll.is_visible = bcoll.name == self.name + + # Find the named bone collection. + if self.name: + try: + solo_bcoll = arm.collections[self.name] + except KeyError: + self.report({'ERROR'}, "Bone collection %r not found" % self.name) + return {'CANCELLED'} + else: + solo_bcoll = arm.collections.active + if not solo_bcoll: + self.report({'ERROR'}, "Armature has no active Bone collection, nothing to solo") + return {'CANCELLED'} + + # Hide everything first. + for bcoll in arm.collections.all: + bcoll.is_visible = False + + # Show the named bone collection and all its ancestors. + while solo_bcoll: + solo_bcoll.is_visible = True + solo_bcoll = solo_bcoll.parent + return {'FINISHED'}