1
$\begingroup$

I've attached a custom PropertyGroup as mystuff to bpy.types.Object, and this group contains a CollectionProperty named my_array and an IntProperty my_array_index to draw a typical UIList with it.

However, I have no clue how I would make an element of the my_array CollectionProperty editable, e.g. so that I can select it from my UIList, display the element in a textbox, modify it and write it back to my CollectionProperty.

My code looks like this:

# A stupid UIList just drawing the elements of the array.
class MyStuffUIList(bpy.types.UIList):
    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
        layout.label(str(item.value))

# Element of the array. It just represents an integer but it seems I cannot use
# bpy.types.IntProperty as base class, then MyStuffProperties fails to register.
class MyStuffPropertiesElement(bpy.types.PropertyGroup):
    value = bpy.props.IntProperty(
        name="Int Value"
    )

# The array attached to objects.
class MyStuffProperties(bpy.types.PropertyGroup):
    my_array = bpy.props.CollectionProperty(
        type=MyStuffPropertiesElement
    )
    my_array_active_index = bpy.props.IntProperty(
        # This is the currently selected index in the UIList representing the array.
    )

# A panel drawing the custom UIList.
class MyStuffPanel(bpy.types.Panel):
    ...
    def draw(self, context):
        ms = context.object.mystuff
        self.layout.template_list("MyStuffUIList", "", ms, "my_array",
                                                       ms, "my_array_active_index")
        # Accessing the array like this isn't possible it seems.
        self.layout.prop(ms, "my_array[my_array_active_index]")
$\endgroup$
  • $\begingroup$ You'd like to create an editable name string or something for each UI list item, right? $\endgroup$ – p2or Jul 8 '16 at 15:52
  • $\begingroup$ Almost; I created a list which displays each element of that array. When I select one entry, I wanna edit it below the list. $\endgroup$ – Ray Jul 8 '16 at 17:07

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.