Hy everyone,
How do I access the element selected in a UI List in order to, for example, put it in a variable to access the data?
template : ui_list_simple.py
Good day,
Hy everyone,
How do I access the element selected in a UI List in order to, for example, put it in a variable to access the data?
template : ui_list_simple.py
Good day,
When you create your own ui list, you also need to create an active property. The property is an IntProperty
, and represents the index of the currently selected list item.
In the ui list example, the active property is obj.active_material_index
.
The active property is passed in layout.template_list()
after the ui list itself:
layout.template_list("UI_LIST", "", obj, "material_slots", obj, "active_material_index")
Specifically this part:
...obj, "active_material_index")
So, you would access the selected material by:
idx = obj.active_material_index
active_mat = obj.material_slots[idx]
Oh, okay, well, thanks for that explanation.
Have a nice day,