Accessing user-defined custom properties and their types

I’d like to access user-defined custom properties (those that can be created by clicking the “+ New” button in the Custom Properties panel) and their type information.

So if I create a custom property in the UI called my_property as a float on the Scene, I can then access the value with bpy.context.scene['my_property']. I can get some subtype information about that property by calling bpy.context.scene.id_properties_ui('my_property').as_dict() which will return this:

{"subtype": "NONE", "description": "Description goes here.", "min": 0.0, "max": 1.0, "soft_min": 0.0, "soft_max": 1.0, "step": 0.10000000149011612, "precision": 3, "default": 1.0}

The problem is that the id_properties_ui method only returns information about the subtype of the property, not the main type. It can be one of Float, Float Array, Integer, Integer Array, Boolean, Boolean Array, String, Data Block, or Python. How do I determine the main type in Python? Where is this stored?

image

Did you try

type(bpy.context.scene['my_property'])

At least for int, float and str this works. For arrays I guess you have to check a bit more. But you can use things like:

len(bpy.context.scene['my_property'])
type(bpy.context.scene['my_property'][0])
1 Like

I guess this is pretty good, even if does take a bit of extra work for arrays. One would believe that there is an enum value buried somewhere in the bpy data that would easily make it clear which type. I mean, blender needs to store this type info somewhere to correctly populate that dropdown, right?

Not sure why it does not work for user defined properties. But if I define a new property in a script and do a registration in the usual way I can access details to that property by this:

bpy.context.scene.bl_rna.properties['my_property']

But user defined properties from the UI do not show up in bpy.context.scene.bl_rna.properties. Looks as if they are managed in a different way. But I never use them and thus I have no idea how and where to check.