0
$\begingroup$

I have different characters in an scene, each one with different bone layers numbers. It is possible, using python, to create a rig ui layer panel for each character based on the armature name, and it is only show when a specific character is selected?

I've been using the flex rig code to create the rig bone layers. But with multiple characters, it doesn't work as I expected. For example, if character A has 5 layers and character B has only 2, toggle the button for layer 1 affects the layers for both characters.

$\endgroup$

1 Answer 1

1
$\begingroup$

If you add a poll method to your panel class you can use whatever criteria you wish to decide if a panel should be shown.

@classmethod
def poll(cls, context):
    return context.active_object.type == 'ARMATURE' and
        context.active_object.name.startswith('myrig')

When you alter the bone layer visibility it should only effect the one active armature. You can perform tests in the panels draw function to decide if a layer button is shown.

def draw(self, context):
    layout = self.layout
    col = layout.column()

    if context.active_object.name.startswith('myrig'):
        row = col.row()
        row.prop(context.active_object.data, 'layers', index=0, toggle=True, text='head')

Unfortunately I don't think there is an easy way to check if there are bones on a layer, you need to loop through all bones and their layers array.

def used_layers(obj):
    ulayers = [False,]*32
    if obj.type == 'ARMATURE':
        for bone in obj.data.bones:
            for i in range(32):
                if bone.layers[i]:
                    ulayers[i] = True
    return ulayers

Then in the draw method -

def draw(self, context):
    layout = self.layout
    col = layout.column()
    show_layers = used_layers(context.active_object)

    if show_layers[0]:
        row = col.row()
        row.prop(context.active_object.data, 'layers', index=0, toggle=True, text='head')
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .