0
$\begingroup$

I'd like to write an operator to set the correct pole angle for IKs, so adding a pole target won't move the rig. As I'd like to add a button next to the pole angle property field in the UI, found out the panel (BONE_PT_constraints), but constraints are listed into sub-layouts in the panel, as the source code has shown.

I don't want to tamper with Blender's original code. Instead, I'd like to go the add-on approach. Thus, using the traditional append-function-to-class approach will only allow me to add controls after the list of constraints.

How to run through the list of sub-layouts so to add the button?

The code I'm using right now follows:

import bpy
import mathutils
import bmesh

def dandrea_IKConstraint_panel(self, context):
    self.layout.operator("constraint.dandrea_adjust_pole", icon='CURSOR', text="Cursor > Selection") #test button
    #for s in self.layout.introspect().split(','):
    #   self.layout.label(s)

class dandrea_adjust_pole(bpy.types.Operator):
    """Adds functionality to the IK constraint panel."""
    bl_idname = "constraint.dandrea_adjust_pole"
    bl_label = "Adjust pole"

    @classmethod
    def poll(cls, context):
        #implement poll
        return True

    def execute(self, context):
        #implement execute
        print ("done.")
        return {'FINISHED'}

def register():
    bpy.utils.register_class(dandrea_adjust_pole)
    bpy.types.BONE_PT_constraints.append(dandrea_IKConstraint_panel)

def unregister():
    bpy.utils.unregister_class(dandrea_adjust_pole)
    bpy.types.BONE_PT_constraints.remove(dandrea_IKConstraint_panel)

if __name__ == "__main__":
    unregister()
    register()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.