No, despite the sound of PointerProperty
, its purpose is not to store a pointer/reference to an ID datablock. Update: you can use it to reference ID datablocks in Blender 2.79 and above, see the other answer.
It's used to organize a set of properties in a nice way, especially if your addon registers a lot of properties:
# Bad, clutters scene objects and may even conflict with other addons
bpy.types.Scene.my_prop_1 = bpy.props.IntProperty()
bpy.types.Scene.my_prop_2 = bpy.props.IntProperty()
bpy.types.Scene.my_prop_3 = bpy.props.IntProperty()
# Good, organize properties as a group
class MyAddonProperties(bpy.types.PropertyGroup):
my_prop_1 = bpy.props.IntProperty()
my_prop_2 = bpy.props.IntProperty()
my_prop_3 = bpy.props.IntProperty()
bpy.types.Scene.my_addon = bpy.props.PointerProperty(type=MyAddonProperties)
# Access it e.g. like
#bpy.context.scene.my_addon.my_prop_1
http://www.blender.org/documentation/blender_python_api_2_69_release/bpy.props.html#propertygroup-example
What you are looking for is bpy.props.IDProperty
, but we don't have that (shame!)
These kind of properties need to be created in C, like Object.parent
.
In Python, you can only store by name (StringProperty
). Use it together with a CollectionProperty
and layout.prop_search().
Note: The StringProperty
isn't tied to the object's name. It's possible to abuse app handlers to check for name changes and to update the property accordingly, but I wouldn't consider it very safe nor efficient.