Python: Is there a way to access subtype/unit of a property? (i.e. value formatting)

Hello everyone. I’m trying to fetch keyframe values and modify them in a popup. I can get the values alright, but I’d like to maintain their original formatting (subtype/unit).

Example: If I’m modifying an angle value (FloatProperty with subtype="ANGLE" ), I’d like to have it displayed the same way. Currently since I’m fetching just the value, I get the equivalent in radians.

I’m wondering, is it possible to access these enum values defined for each property? Could they be accessed from the fcurve, or does the fcurve stores a reference to the name of the property?

Thanks!

EDIT: Rephrased the post for better clarity.

As I understand, internally we store angles as radians because that is how we do trigonometry. When we display values to the user, they are converted to degrees since numbers like pi/4 make people squirrely.
(corrections welcome!)

Yes, perhaps I wasn’t clear. I’ve done a bit more research, let me rephrase:
What I’m specifically trying to get is the subtype/unit of the property, so that I can display it the same way in the popup. There are enums both for subtype and unit containing the values I’m trying to get. I just don’t know how to trace back to get them from a keyframe value.

The subtype and unit of a property can be accessed through bl_rna. For example the subtype for rotation_euler of an object would be accessed like this:

bpy.context.object.bl_rna.properties["rotation_euler"].subtype

The unit can be accessed in a similar way:

bpy.context.object.bl_rna.properties["rotation_euler"].unit

4 Likes

Wonderful, thank you!

1 Like

This is helpful. Anyone know if it is possible to dynamically change these values since they are read-only. I mainly want to find a way to change the precision value of custom properties.

1 Like

I’m not sure, I didn’t delve that much on dynamic properties.

What I was trying to do I solved it by just making a temporal dummy property inside bpy.types.Scene (I assume you can make it anywhere you need) using all of the original property’s parameters.
Perhaps you can do this to alter what you want? Maybe not a temp one but directly overwrite the custom property with everything the same except what you’re trying to change.

1 Like