3

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)
  • 1
    Is your question about how to display a custom name per object? What's the goal? Related: https://blender.stackexchange.com/questions/30444/create-an-interface-which-is-similar-to-the-material-list-box/30446#30446 also see: https://blender.stackexchange.com/a/159353/31447 – brockmann Jan 04 '21 at 21:28
  • 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). – Sighthound Jan 06 '21 at 17:23

1 Answers1

3

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
Anson Savage
  • 3,392
  • 3
  • 31
  • 67
kemplerart
  • 610
  • 1
  • 10