6

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.

user15546
  • 63
  • 5
  • 1
    related: http://blender.stackexchange.com/questions/6975/is-it-possible-to-use-bpy-props-pointerproperty-to-store-a-pointer-to-an-object – p2or Jul 14 '15 at 10:28

1 Answers1

5

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
CodeManX
  • 29,298
  • 3
  • 89
  • 128
  • 2
    Worth noting that you can use collections for UI-Lists (as used for vertex-groups, UV-layers... etc) – ideasman42 Jul 15 '15 at 01:27
  • Where can I find all the methods applicable for a collection, like add() and remove() and their documentation? Thank you for you answers! – user15546 Jul 29 '15 at 12:21
  • 1
    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(). – CodeManX Jul 29 '15 at 17:03