3
$\begingroup$

I'm trying to initialize a PropertyGroup with pointers to objects inside another PropertyGroup. I'm getting an error: bpy_struct "ListItem" registration error: object_group could not register. Am I doing something wrong? In principle I'm trying to hold pointers to objects in a list, with each list with a label. Answer from here doesn't seem to be working:Register Object inside of Another Object

class ObjectPointer(PropertyGroup):

    obj: bpy.props.PointerProperty(type = bpy.types.Object)

class ListItem(PropertyGroup):

    name: StringProperty(
        name = "Name"
    )

    object_group: CollectionProperty(type = objectPointer)

Inside register():

bpy.types.Scene.my_list = CollectionProperty(type = ListItem)
$\endgroup$
2
  • 1
    $\begingroup$ Is your question about how to display a custom name per object? What's the goal? Related: blender.stackexchange.com/questions/30444/… also see: blender.stackexchange.com/a/159353/31447 $\endgroup$
    – brockmann
    Commented Jan 4, 2021 at 21:28
  • $\begingroup$ Make sure you register ObjectPointer first, then ListItem and finally assign it to my_list in the register function. Also make sure (type = objectPointer) is written like (type = ObjectPointer) (ObjectPointer with capital O, but might be just a typo in your question). $\endgroup$
    – Sighthound
    Commented Jan 6, 2021 at 17:23

1 Answer 1

3
$\begingroup$

Here is all you need to do:

class ObjectPointer(PropertyGroup):

    obj: bpy.props.PointerProperty(type = bpy.types.Object)

class ListItem(PropertyGroup):

    name: StringProperty(
        name = "Name"
    )

    object_group: CollectionProperty(type = ObjectPointer)

Inside register() - here are changes:

bpy.utils.register_class(ObjectPointer) #firstly register collection property type
bpy.utils.register_class(ListItem) #the one where you use ObjectPointer after
bpy.types.Scene.my_list = CollectionProperty(type = ListItem) #lastly assign
$\endgroup$

You must log in to answer this question.

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