Blender Python convert units to imperial

I'm writing a script that needs to make geometry using imperial units. The scene is set to imperial however this has no effect on Pythons end of things. I need to know the value that equates to an inch when using traslate functions.

Note this is not a duplicate of another question asking to get imperial lengh from Blender units.

If it isn't a duplicate q, the answer can certainly be gleaned from the q marked as dupe Is there a bpy function to convert from blender units to Imperial?

scale /= 0.3048  # BU to feet


which pretty much comes from 1bu = 1 metre

import bpy
import space_view3d_panel_measure as pm
scene = bpy.context.scene
uinfo = pm.getUnitsInfo()

def bu_to_inches(scene, d):
scale = scene.unit_settings.scale_length
# 1bu = 1 / 0.3048 ft
return 12 * scale * d / 0.3048

def inches_to_bu(scene, d):
return d / bu_to_inches(scene, 1)

# 1 bu in scene units
x = pm.convertDistance(1, uinfo)
print(x)
# 1 bu in inches
x = bu_to_inches(scene, 1)
print(x)

# 12.33 bu in scene units
x = pm.convertDistance(12.33, uinfo)
print(x)
# 12.33 bu in inches
x = bu_to_inches(scene, 12.33)
print(x)
# how many inches 12.33 bu is to bu
print(inches_to_bu(scene, x))
# how many bu 1 inch is
print(inches_to_bu(scene, 1))

• Can someone please explain the factor 12 in the conversion in 'bu_to_inches'? Commented Sep 28, 2020 at 9:51
• The comment mentions a blender unit in relation to feet. There are 12 inches in a foot. Commented Sep 28, 2020 at 10:25
• The space_view3d_panel_measure  module is not available in new versions of Blender. Anyone know if it was removed, or if there's a replacement? Commented Sep 30, 2021 at 21:55

1ft = 0.3048
1in = 0.0254


As a note to others reading this thread batFINGER's answer includes space_view3d_panel_measure module which is solely for printing out units in an easy human readable format and is not needed for unit conversion. His script also includes 'scale' which is the scale value set in propertys/scene/units/scale. Unless you are using a scale other than 1 (default) it to is unnecessary although it would be good if your script will be used by other people in which case you never know if someone is messing with scale settings or not.

The simplest way of doing unit conversion is...

distance = 2+(11/16)
inch = 0.0254

distance *= inch


Here distance is the value in inches we want converted. In this case we did 2+(11/16) to demonstrate how we would include a fraction. Its the same as saying 2" 11/16" in real life. The simple equation "distance *= inch" will convert distance from inches to Blender Units.

Below we can demonstrate a translation by moving the X axis of a selected object by 2" 11/16"

bpy.ops.transform.translate(value=(distance, 0, 0))


A full script example for this is...

import bpy

inch = 0.0254
distance = 2+(11/16)
distance *= inch

bpy.ops.transform.translate(value=(distance, 0, 0))

• As a note to those who have down voted this answer, I put this here because the OP explicitly asked for the value that equates to one inch which is 0.0254. That value was not explicitly given by other answer(s). Commented Apr 1, 2016 at 7:32
• It would be nice to add the correction needed when the user does tinker with the scaling factor. Commented Jan 9, 2023 at 20:18

Use:

bpy.ops.script.execute_preset(filepath="C:\\Program Files\\Blender Foundation\\Blender\\2.78\\scripts\\presets\\units_length\\inches.py",

I was messing with the area() function and noticed that the returned value wasn't changing when I altered the grid size or the Scene Properties units.