[Bf-committers] properties per datablock & python

Joe Eagar joeedh at gmail.com
Wed May 21 19:04:17 CEST 2008

ID properties are basically the new custom property system in blender.  
They were originally attached only to datablocks (which is where the 
name comes from, since datablocks all include the struct ID in the C 
source code).  They're also used in pyconstraints.

Using them isn't too difficult. . .basically you assign different simple 
primitive python types to a property, and the code will parse the type 
into an id property automatically (or throw an error if it could not).

For example:

object.properties["string"] = "sdfdsf"
object.properties["float"] = 1.0
object.properties["int"] = 1

#only numeric arrays allowed, also if one element is a float number then
 the array is assumed to be a float array.
object.properties["array"] = [0, 1, 2, 3, 4, 5.0]

object.properties["group"] = {"float": 1.0, "array": [0.0, 1.0, 2.0], 
"subgroup": {"string": "ssdfsd"}}

Look at the pydocs for more information.  Note that these do not replace 
game properties, which are specific to the game engine (for example, a 
timer property wouldn't have much meaning outside the game engine).

One big warning: As always with our API, do NOT keep references to id 
properties floating around.  This *will* cause crashes.  Always re-get 
the reference whenever you need it.  This is true for most things in the 
api as well, btw.


Jonathan-David SCHRODER wrote:
> hey
> while doing research for annotating objects with some details (for the 
> blender repo client framework project)
> - I stumbled upon a blending into python book entry here : 
> http://en.wikibooks.org/wiki/Blender_3D:_Blending_Into_Python/Custom_datablock_properties
> - and a 2.42 python api release log on bf-committers which dates back 
> to january 2007 :
> * Blender lib data - Added IDproperties to most libdata - a way you can
> assign arbitrary properties data to any Blender libdata.
> [...]
> Ton has two items on his todo before bcon4
> * buttons/panel for custom properties
> * cache limitor for new image code
> the second item might get punted to after 2.43
> [...]
> -there's also the python api related page (for objects here but the 
> properties attribute exist for all kinds of datablocks) where you can 
> see the IDGroup:properties attribute :
> http://www.blender.org/documentation/246PythonDoc/Object.Object-class.html
> do you know if some GUI work has been done in C or python to be able 
> to display&edit non game engine custom properties ?
> Do you also know what projects use this IDGroup:properties python 
> functionnality ? There's just things that look like proposals blending 
> into python on the wikibook).
> I'd be ok to do something in python + gui to be able to do show+edit 
> for all those custom properties, because this relates to the repo 
> client project I'm working on
> (in our case : details on the original author of the object, date 
> published, parent blend file it originates from, repository adress it 
> originates from....)
> jonathan
> -- 
> http://www.jaxtr.com/myselfhimself
> ------------------------------------------------------------------------
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers

More information about the Bf-committers mailing list