← All ideas
  • Published 1 Jun 2023

Multiple units across the same project / custom units

I'm working on architectural addon and it's storing a lot of BIM data in all kind of units.

In Blender Python API there is very convenient option to specify property subtype / unit.

For example, you specify it as "LENGTH" and it's now displaying it in default project units - "5 m", "500 cm", etc. Which is very human way to read and input the data given that you can type in "5 km" and it will be automatically converted.

Screenshot 2023-06-01 102453.png

My proposal is to add an option to specify what units exactly should the property use. Because sometimes you want to have option to specify small and big values in the same project and want some property to always display the data in meters or millimeters even if project's units were set to something else.

There is option to use adaptive units but atleast from my workflow I usually want to see length data in mm and sometimes convert it to meters. Same with time - most of the time I want it to be in seconds but for some properties I need it in minutes/hours.


And another suggestion - add an option to display custom units symbols for number properties.

Example:

test_prop: bpy.props.FloatProperty(name="Test", custom_unit="Hz")

Will display all values from this property like "100 Hz", "500 Hz" etc. It seems robust and can help easily support more units and make properties a bit more clear about what units they use. It also will be possible to give the power to display custom units to all Blender users with custom properties, not just for the properties created from Python API.

There is also an option to go step further and to add formatting value function.

def format_value(self, value):
    if value < 10**3:
        return f"{value} Hz"
    if value < 10**6:
        return f"{value/10**3} kHz"
    return return f"{value/10**6} MHz"

class TestProperties(bpy.types.PropertyGroup):
    test_prop: bpy.props.FloatProperty(name="Test", format_value = format_value)

And there is even further step where it would be possible to preprocess value so users would be able to type in "5 MHz" and it will automatically interpreted and stored as 5 million Hertz but displayed as "5 MHz" using format_value .

But just adding support for inline custom units would be a great start.

75%

Development Status: Open

Upvote 3 Downvote 1
andrej730
1 Jun 2023

0 Comments