2
$\begingroup$

I'm trying to write and addon that will display modifiers in a listbox, with the selected modifiers settings displayed below. But can't accomplish it because the template_list function requires an active index to reference the selection, which doesn't exist in the case of modifiers. here's an example comparing the list for vertex groups and the list for modifiers.

The modifier list throws an error because as far as I know, there is no "active_index" for modifiers - their just in a static state. How can I assign an index to reference the individual modifiers and select them from the listbox to operate on them, such as changing properties? Could I use a custom property or is there a better way to do this?

The thing is, there must be an index because the list box ordering updates according to the modifier stack - I just need to know how to access it if possible, and pass it to the list box.

please be explicit because I'm no expert here, thanks.

    ob = bpy.context.object

    row = layout.row()
    row.template_list("MESH_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups,"active_index", rows=rows)

    row = layout.row()
    row.template_list("UI_UL_list", "list", ob, "modifiers",ob.modifiers, "active_index",rows=rows)
$\endgroup$
2
$\begingroup$

You can create a simple IntProperty() to be used as active index storage.

bpy.types.Object.modifier_active_index = bpy.props.IntProperty()

# ...

row.template_list("UI_UL_list", "list", ob, "modifiers", ob, "modifier_active_index", rows=rows)
$\endgroup$
  • $\begingroup$ should work, I'll have to cross reference the object.modifiers list to get the active selection. thanks! $\endgroup$ – russcript Jul 4 '14 at 20:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.