Skip to content
Snippets Groups Projects
Commit 9f6319db authored by Ines Almeida's avatar Ines Almeida
Browse files

[Selection Sets] Tweaks and optimizations

parent 70a88905
No related branches found
No related tags found
No related merge requests found
...@@ -84,8 +84,7 @@ class POSE_PT_selection_sets(Panel): ...@@ -84,8 +84,7 @@ class POSE_PT_selection_sets(Panel):
def poll(cls, context): def poll(cls, context):
return (context.object return (context.object
and context.object.type == 'ARMATURE' and context.object.type == 'ARMATURE'
and context.object.pose and context.object.pose)
)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
...@@ -94,6 +93,7 @@ class POSE_PT_selection_sets(Panel): ...@@ -94,6 +93,7 @@ class POSE_PT_selection_sets(Panel):
arm = context.object arm = context.object
row = layout.row() row = layout.row()
row.enabled = (context.mode == 'POSE')
# UI list # UI list
rows = 4 if len(arm.selection_sets) > 0 else 1 rows = 4 if len(arm.selection_sets) > 0 else 1
...@@ -159,12 +159,12 @@ class POSE_OT_selection_set_add(PluginOperator): ...@@ -159,12 +159,12 @@ class POSE_OT_selection_set_add(PluginOperator):
def execute(self, context): def execute(self, context):
arm = context.object arm = context.object
selection_set = arm.selection_sets.add() new_sel_set = arm.selection_sets.add()
# naming # naming
selection_set.name = "SelectionSet" new_sel_set.name = "SelectionSet"
if POSE_OT_selection_set_add.created_counter > 0: if POSE_OT_selection_set_add.created_counter > 0:
selection_set.name += ".{:03d}".format(POSE_OT_selection_set_add.created_counter) new_sel_set.name += ".{:03d}".format(POSE_OT_selection_set_add.created_counter)
POSE_OT_selection_set_add.created_counter += 1 POSE_OT_selection_set_add.created_counter += 1
# select newly created set # select newly created set
...@@ -201,17 +201,17 @@ class POSE_OT_selection_set_assign(NeedSelSetPluginOperator): ...@@ -201,17 +201,17 @@ class POSE_OT_selection_set_assign(NeedSelSetPluginOperator):
def execute(self, context): def execute(self, context):
arm = context.object arm = context.object
pose = arm.pose pose = arm.pose
act_sel_set = arm.selection_sets[arm.active_selection_set]
#if arm.active_selection_set <= 0: #if arm.active_selection_set <= 0:
# arm.selection_sets.add() # arm.selection_sets.add()
#TODO naming convention #TODO naming convention
# return {'FINISHED'} # return {'FINISHED'}
selection_set = arm.selection_sets[arm.active_selection_set] # iterate only the selected bones in current pose that are not hidden
for bone in pose.bones: for bone in context.selected_pose_bones:
if (bone.bone.select and not bone.bone.hide if bone.name not in act_sel_set.bone_ids:
and bone.name not in selection_set.bone_ids): bone_id = act_sel_set.bone_ids.add()
bone_id = selection_set.bone_ids.add()
bone_id.name = bone.name bone_id.name = bone.name
return {'FINISHED'} return {'FINISHED'}
...@@ -226,14 +226,13 @@ class POSE_OT_selection_set_unassign(NeedSelSetPluginOperator): ...@@ -226,14 +226,13 @@ class POSE_OT_selection_set_unassign(NeedSelSetPluginOperator):
def execute(self, context): def execute(self, context):
arm = context.object arm = context.object
pose = arm.pose pose = arm.pose
act_sel_set = arm.selection_sets[arm.active_selection_set]
selection_set = arm.selection_sets[arm.active_selection_set] # iterate only the selected bones in current pose that are not hidden
for bone in context.selected_pose_bones:
for bone in pose.bones: if bone.name in act_sel_set.bone_ids:
if (bone.bone.select and not bone.bone.hide idx = act_sel_set.bone_ids.find(bone.name)
and bone.name in selection_set.bone_ids): act_sel_set.bone_ids.remove(idx)
idx = selection_set.bone_ids.find(bone.name)
selection_set.bone_ids.remove(idx)
return {'FINISHED'} return {'FINISHED'}
...@@ -247,11 +246,11 @@ class POSE_OT_selection_set_select(NeedSelSetPluginOperator): ...@@ -247,11 +246,11 @@ class POSE_OT_selection_set_select(NeedSelSetPluginOperator):
def execute(self, context): def execute(self, context):
arm = context.object arm = context.object
pose = arm.pose pose = arm.pose
act_sel_set = arm.selection_sets[arm.active_selection_set]
selection_set = arm.selection_sets[arm.active_selection_set] for bone in context.visible_pose_bones:
for bone in pose.bones: if bone.name in act_sel_set.bone_ids:
if not bone.bone.hide and bone.name in selection_set.bone_ids: bone.bone.select = True
bone.bone.select = True
return {'FINISHED'} return {'FINISHED'}
...@@ -265,10 +264,10 @@ class POSE_OT_selection_set_deselect(NeedSelSetPluginOperator): ...@@ -265,10 +264,10 @@ class POSE_OT_selection_set_deselect(NeedSelSetPluginOperator):
def execute(self, context): def execute(self, context):
arm = context.object arm = context.object
pose = arm.pose pose = arm.pose
act_sel_set = arm.selection_sets[arm.active_selection_set]
selection_set = arm.selection_sets[arm.active_selection_set] for bone in context.selected_pose_bones:
for bone in pose.bones: if bone.name in act_sel_set.bone_ids:
if not bone.bone.hide and bone.name in selection_set.bone_ids:
bone.bone.select = False bone.bone.select = False
return {'FINISHED'} return {'FINISHED'}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment