I want to read out Custom Properties of a Blender Object using the scripting mode in Blender itself. So far I found only possibilities to read out Custom Properties you created yourself in the scripting mode. But I want to read out Custom Properties which I tagged myself per hand. This means I dont have a local variable to use.
I want this to be in the following context: I have a Loop going through all objects:
for obj in bpy.data.objects:
if not 'Camera' in obj.name and not 'Lamp' in obj.name and not 'Armature' in obj.name:
#here I get the location of the current Object
loc.append(obj.location)
Now what would be perfect, would be something like:
obj.getCustomProperties
Is there a way to do this with the Blender Python mode?
Thanks, Daniel
Python in Blender This interpreter runs scripts to draw the user interface and is used for some of Blender's internal tools as well. Blender's embedded interpreter provides a typical Python environment, so code from tutorials on how to write Python scripts can also be run with Blender's interpreter.
Custom properties are a way to store your own metadata in Blender's data-blocks which can be used for rigging (where bones and objects can have custom properties driving other properties), and Python scripts, where it's common to define new settings not available in Blender.
Let's say we add a custom property called 'testprop' to object 'Cube' - you can access that property within python as bpy.data.objects['Cube']['testprop']
If you don't know the property names you can get a list of available custom properties by calling keys() for the object.
This leads to the following to print the custom properties -
bad_obj_types = ['CAMERA','LAMP','ARMATURE']
for obj in bpy.data.objects:
if obj.type not in bad_obj_types:
if len(obj.keys()) > 1:
# First item is _RNA_UI
print("Object",obj.name,"custom properties:")
for K in obj.keys():
if K not in '_RNA_UI':
print( K , "-" , obj[K] )
You may also notice I test obj.type instead of obj.name which can be changed by the user and also multiple items may exist with numeric extensions in the name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With