Last active
August 4, 2019 09:28
-
-
Save natecraddock/150bde4e879d71ec57e2b54b2c56ee4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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