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
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.
Related :
This github has a Python script to read from a csv file and update the Custom Properties for a mesh(es):
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.