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.
This commit is contained in:
Sybren A. Stüvel
2024-01-08 14:34:00 +01:00
parent ef5dd0e451
commit 2274f2be4b

View File

@@ -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'}