5
$\begingroup$

I noticed that bpy.props.CollectionProperty and bpy.props.PointerProperty can both be used to collect custom properties (as is shown here: http://www.blender.org/api/blender_python_api_2_75_release/bpy.props.html).

There are also other examples on the internet, but I still can't figure out the difference between these two properties.

$\endgroup$
1

1 Answer 1

3
$\begingroup$

A collection is an array of a set of properties. Every element in the array has the same properties (with individual values).

A pointer property is used to organize properties. The sub-attribute the pointer property is stored at will hold a set of properties. It is not an array of properties however.

Scene.collection
  Scene.collection.add()
  Scene.collection.remove()
  Scene.collection ...()
  Scene.collection[0]
    Scene.collection[0].name # Foo
    Scene.collection[0].val # 123
  Scene.collection[1]
    Scene.collection[1].name # Bar
    Scene.collection[1].val # 234
  Scene.collection[...]
    Scene.collection[...].name # Baz
    Scene.collection[...].val # 345

Scene.pointer
  Scene.pointer.name # Foo
  Scene.pointer.val # 123
$\endgroup$
3
  • 2
    $\begingroup$ Worth noting that you can use collections for UI-Lists (as used for vertex-groups, UV-layers... etc) $\endgroup$
    – ideasman42
    Jul 15, 2015 at 1:27
  • $\begingroup$ Where can I find all the methods applicable for a collection, like add() and remove() and their documentation? Thank you for you answers! $\endgroup$
    – user15546
    Jul 29, 2015 at 12:21
  • 1
    $\begingroup$ They are unfortunately not documented, you'll need to use dir(...) on an actual collection or use auto-complete of the Python Console. There are actually just two more important methods however, clear() and move(). $\endgroup$
    – CodeManX
    Jul 29, 2015 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.