6
$\begingroup$

Is there a bpy function to convert from blender units to Imperial? something like:

   >>> blender_to_imperial(2.0)
   ... 6.562'

This functionality is present when showing edge lengths, but I can't seem to find a function that can return the conversion.

I found one in the caliper script by macouno, but am wondering if this isn't something that exists already in bpy.

$\endgroup$
6
  • $\begingroup$ I don't think imperial merits a tag.. $\endgroup$
    – iKlsR
    Commented Jun 14, 2013 at 20:50
  • $\begingroup$ it wasn't an arbitrary tag choice. $\endgroup$
    – zeffii
    Commented Jun 14, 2013 at 20:58
  • $\begingroup$ ok, you could document it then. I can't imagine any real use of this tag, it will probably be synonymized into a larger one sooner or later, one that will account for all units. $\endgroup$
    – iKlsR
    Commented Jun 14, 2013 at 21:01
  • $\begingroup$ I don't personally use Imperial units, perhaps dimensions or dimensioning would be better $\endgroup$
    – zeffii
    Commented Jun 14, 2013 at 21:16
  • 1
    $\begingroup$ if it starts to crop up a lot definitely a meta post - good point and worth talking about. $\endgroup$
    – zeffii
    Commented Jun 14, 2013 at 21:30

2 Answers 2

6
$\begingroup$

I found several internal conversion code in the source, like one in view3d_ruler.c for bpy.ops.view3d.ruler(), or in drawobject.c for measurement stats, none of them with direct Python interface. No reference to it, too, in the API manual.

CMIIW, but I think we'll have to write one. All distributed addons so far, like Measure Panel, also write their own conversion function, and it looks like the aforementioned addon have several function we can use directly:

import space_view3d_panel_measure as pm

uinfo = pm.getUnitsInfo()    
print(pm.convertDistance(2, uinfo)) # prints 2.0m, 2.0 BU, or 6.56168'
                                    # depending on selected unit system.
$\endgroup$
2
  • $\begingroup$ cool, yeah seems like a basic requirement for international 'precision' based modelling tools, and nice to have a solid implementation to call at will. $\endgroup$
    – zeffii
    Commented Jun 14, 2013 at 20:45
  • $\begingroup$ this method works fine @Adhi, thank you! And using it in the edge sum script: gist.github.com/zeffii/3839812 $\endgroup$
    – zeffii
    Commented Jun 14, 2013 at 21:13
1
$\begingroup$

The question is old and now Blender has built-in utilities to convert text input to internal units, for example you can set 2in like this:

bpy.utils.units.to_value("IMPERIAL", "LENGTH", "2in")

Read more: https://docs.blender.org/api/current/bpy.utils.units.html

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .