Hello!
I have made a rig that will have a functioning panel. The problem is that it’s not as I want it to be.
So I’ve grabbed some pieces off the web and templates form riggify. I don’t understand it most of it but the sliders in the upper part should be sensitive to what bone is selected, Like in the lower section. BUT I have only got it to work with one bone. I want to use an array with about 5 bones, and when one of them is selected the section should appear. In the second one I have the code that is selection sensitive.
So…
How do I do it if I want it to have the panel properties to be able to be visible for multiple bones. I’m thinking arrays, but I don’t know … :spin:
import bpy
rig_name = "test_rig"
class MinecraftRigProperties(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Rig Menu"
@classmethod
def poll(self, context):
try:
return (context.active_object.data.get("rig_name") == rig_name)
except (AttributeError, KeyError, TypeError):
return False
def draw(self, context):
layout = self.layout
col = layout.column()
pose_bones = context.active_object.pose.bones
col.label(text="Arm IK Switches")
col.prop(pose_bones["root"], '["ik/fk_arm.L"]', text="IK/FK Left Arm", slider=True)
col.prop(pose_bones["root"], '["ik/fk_arm.R"]', text="IK/FK Right Arm", slider=True)
col.label(text="Arm Stretching (IK Only)")
col.prop(pose_bones["root"], '["stretch_arm.L"]', text="Stretch Left Arm", slider=True)
col.prop(pose_bones["root"], '["stretch_arm.R"]', text="Stretch Right Arm", slider=True)
col.label(text="Legs")
col.prop(pose_bones["root"], '["ik/fk_leg.L"]', text="IK/FK Left Leg", slider=True)
col.prop(pose_bones["root"], '["ik/fk_leg.R"]', text="IK/FK Right Leg", slider=True)
col.label(text="Subsurf")
col.prop(pose_bones["root"], '["subsurf"]', text="Subsurf", toggle=True)
col.label(text="- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
The part with sensitive props.
try:
selected_bones = [bone.name for bone in context.selected_pose_bones]
selected_bones += [context.active_pose_bone.name]
except (AttributeError, TypeError):
return
def is_selected(names):
# Returns whether any of the named bones are selected.
if type(names) == list:
for name in names:
if name in selected_bones:
return True
elif names in selected_bones:
return True
return False
#IK Switches
ik_foot_right = "CTRL_IK_leg.L"
if is_selected([ik_foot_right]):
col.prop(pose_bones["root"], '["ik/fk_leg.L"]', text="IK/FK Leg Right", slider=True)
ik_foot_right = "CTRL_IK_leg.R"
if is_selected([ik_foot_right]):
col.prop(pose_bones["root"], '["ik/fk_leg.R"]', text="IK/FK Lega Left", slider=True)
def register():
bpy.utils.register_class(MinecraftRigProperties)
def unregister():
bpy.utils.unregister_class(MinecraftRigProperties)
if __name__ == "__main__":
register() to only be shown