Skip to content

Instantly share code, notes, and snippets.

@natecraddock
Last active August 4, 2019 09:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natecraddock/150bde4e879d71ec57e2b54b2c56ee4e to your computer and use it in GitHub Desktop.
Save natecraddock/150bde4e879d71ec57e2b54b2c56ee4e to your computer and use it in GitHub Desktop.
import bpy
class RigLayers(bpy.types.Panel):
bl_idname = 'POSE_PT_RigLayers'
bl_label = "Rig Layers"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_context = "posemode"
bl_category = 'CUSTOM_CATEGORY'
bone_groups ={
'Root bone': 0,
'FK bones': 1,
'IK bones': 2,
'Facial bones':3,
'Manual spine':14
}
control_layers = [0,1,2,3,14]
total_layers = 20
def draw(self, context):
column = self.layout.column() #items are placed under each other in a column
contexts = []
for item in self.bone_groups.keys():
column.prop(context.active_object.data, 'layers',
index=self.bone_groups[item],
toggle=True, text=item,
emboss=True)
# Callback function for bone layer changes
def bone_layer_update_callback(ob):
# Do something here
print("Bone layers changed on object: ", ob.name)
# Subscribe to bone layers for a specific armature
def subscribe_to_bone_layers(ob):
if ob.type != 'ARMATURE':
return
subscribe_to = ob.data.path_resolve("layers", False)
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=ob,
args=(ob,),
notify=bone_layer_update_callback,
)
# Ensure only armatures are passed to this function
subscribe_to_bone_layers(bpy.context.object)
# Register panel
bpy.utils.register_class(RigLayers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment