Unit system and consistent defaults values in python.
Addon devs using python to define objects size always are facing with international units issues.
Expecting a single default value to generate same result whatever the unit system choosen. As it, it is not the case, but fortunately there is a simple solution to handle this and fix all those issues at once.
When going from/to internal <-> ui, unit transforms occurs this way:
- Ui -> unit conversion -> size in meter / unit scale = internal
- Internal * unit scale = size in meter -> unit conversion -> Ui
If we apply same rule to defaults, an object with a default set to 1 will then be scaled by choosen unit, eg: 0.3048 meter when unit is imperial feet.
Handling default values properly:
Unit conversion must not occur on default values !
We
must only divide default by unit scale
and always define default values as meter.
This way
objects size will remains consistent
and correct whatever the unit system is.
- default -> size in meter / unit scale = Internal.
So a cube with 1 (meter) as default will remains the same cube when created using imperial feet as unit.
2 Comments
Agreed, if the addon needs to have some explicit size with respect to a particular unit of measurement, the python API should provide developers with a way to invoke it intentionally.
Perhaps this unsuccessful attempt is similar to the one sought ...
I tried something like this:
based on jayaman python preview: youtube.com/watch
But i run into this error with PropertyGroup etc.
archive.blender.org/wiki/index.php/Extensions:2.6/Py/API_Changes/
The unit system length can be shown in a label: