1
$\begingroup$

NLA Editor page, clicked in an NLA Strip; inside the Strip settings panel there's two custom UI elements: a 'UI List' with two 'custom settings' underneath. Changing the custom settings underneath changes what's displayed in the UI List

I've got this UI element, outlined in red in the image, in the NLA Editor. I can make the UI elements, but I need help with the logic.

  1. How can the 'UI List' contain just the two custom properties shown beneath it, rather than a reference to materials or whatever, and allow them to be edited and updated/saved?

  2. Please See Pt.2 at: 'List' of Properties in NLA Strip Pt.2

Thank you for any help you can give.

$\endgroup$
1

1 Answer 1

1
$\begingroup$

This is adapted from Using UILists in Blender

One way is to create a class that holds the custom properties for each list item. Each item should have a name, so you might want a class with three items in it:

from bpy.props import StringProperty, FloatProperty
from bpy.types import PropertyGroup

class ListItem(PropertyGroup):
    """Group of properties representing an item in the list."""

    name: StringProperty(
           name="Name",
           description="A name for this item",
           default="Untitled")

    custom_prop_1: FloatProperty(
           name="Custom Property 1",
           description="a floating point property",
           default=0.0)

    custom_prop_2: StringProperty(
            name="Custom Property 2",
            description="a string property",
            default="")

To make the class available, put it in a collection

from bpy.props import CollectionProperty

# Add this line to the register function
    bpy.types.Scene.my_list = CollectionProperty(type = ListItem)

where the Scene might not be the correct type to attach the list to but works for a demonstration. Because you want users to be able to modify the list you'll also want an index property, so add this line to the register function:

    bpy.types.Scene.list_index = IntProperty(name = "Index for my_list",
                                             default = 0)

Where, again, Scene might not be the correct type. More about that in part 2.

To allow users to edit the list, you need a 'widget' (UIList subclass) and a couple of operators, one to add items and one to delete them. Since you've said you know the UI part, I won't paste the ones from the Sinestra tutorial, but the key is that the add operator calls context.scene.my_list.add() and the remove operator calls context.scene.my_list.remove() from their execute routines.

The 'widget' you have in your screenshot has those functions, along with the buttons needed to move items around in the list; so I won't elaborate further.

$\endgroup$
2
  • $\begingroup$ Thank you, Marty. I'll try it out. $\endgroup$
    – Candle
    Jan 5, 2022 at 15:17
  • $\begingroup$ Took a while to figure it out but today I got it almost working. Thank you for the help, your explination really did help me see how all the parts connect together. $\endgroup$
    – Candle
    Jan 10, 2022 at 19:39

You must log in to answer this question.

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