0
$\begingroup$

Lets say I have defined a new class

class MyNewObject(bpy.types.PropertyGroup):
    name: bpy.props.StringProperty(name = "name", default = "")
    minimum: bpy.props.FloatProperty(name = "min", default = 0.0)

    # Additional code not shown here
    # ...
    # ...
    # ...

Now, if I want to add an attribute storing a list of different objects (which could be a Blender Camera, or anything else, like another custom-defined object), what should be the bpy.props to use?

$\endgroup$
3
  • 1
    $\begingroup$ I would use either bpy.props.EnumProperty for general lists of "anything", or bpy.props.EnumProperty for objects, especially if they need to be defined by the user. $\endgroup$
    – Lauloque
    Commented Nov 23, 2023 at 22:55
  • $\begingroup$ @L0Lock Good to know, thank you $\endgroup$
    – aheuchamps
    Commented Nov 24, 2023 at 6:49
  • $\begingroup$ I noticed in my previous comment I wrongly inserted the second link, it was supposed to be CollectionProperty x) but @Mr A's answer explains better anyway. $\endgroup$
    – Lauloque
    Commented Nov 24, 2023 at 15:41

1 Answer 1

2
$\begingroup$

You would use a bpy.props.CollectionProperty(type=MyNewObject, name="Insert Name Here"). The type parameter should match your class name. You can check the docs for more information.


Edit: As mentioned in the comments, bpy.props.PointerProperty is also an option. This is its entry in the docs. There is also this example and this example which show how to use them. As you can see, the first is used when you just want one instance of your custom property, and the second is used when you have more than one.

$\endgroup$
3
  • $\begingroup$ What would the advantage(s)/disadvantage(s) of a bpy.props.CollectionProperty be with respect to the comment of @L0Lock here above? $\endgroup$
    – aheuchamps
    Commented Nov 24, 2023 at 6:52
  • 2
    $\begingroup$ enum props store strings when pointer property / collection property stores the adresse to actual objects $\endgroup$
    – Gorgious
    Commented Nov 24, 2023 at 8:33
  • 2
    $\begingroup$ @aheuchamps As @Gorgious said, bpy.props.EnumProperty is incompatible with your custom bpy.types.PropertyGroup. Your options are bpy.props.PointerProperty and bpy.props.CollectionProperty. I will update my answer to include it. $\endgroup$
    – Mr A
    Commented Nov 24, 2023 at 9:17

You must log in to answer this question.

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