1
$\begingroup$

I'm writing some UI where, for each material slot an object has, there is an interface that involves a button. I need this button to know which material slot index it is associated with, but I can't quite figure out how to do it. My UI code looks something like this:

        for i in range(len(object.material_slots)):
            current_material_slot = object.material_slots[i]
            box.label(text="Material Slot " +  str(i))
            row = box.row()
            row.operator('my_list.delete_item', icon = 'REMOVE', text='Remove')

One thing I tried doing was adding an IntProperty to the operator and then informing the operator which int property it had doing something like this, but apparently row.operator() returns None, so that didn't work either.

        remove_button = row.operator('my_list.delete_item', icon = 'REMOVE', text='Remove')
        remove_button.material_slot_index = i

(To avoid confusion, I'm not trying to make a button that removes the material slot; I have a template_list associated with each material slot, and I'm removing items from this template_list.)

What's the best way to let the remove button know which material slot its associated with?

Thanks!

$\endgroup$

1 Answer 1

1
$\begingroup$

Actually, the reason that remove_button = row.operator('my_list.delete_item', icon = 'REMOVE', text='Remove') returned None was because my operator wasn't registered. Now that it's registered, this code is working surprisingly well!

Definitely let me know if this is bad practice or anything, but it seems to be doing the job...

$\endgroup$

You must log in to answer this question.

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