How do i read out Custom Properties in Blender with Python?

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.

Tags:

Python

Blender