3

I'm working on a way to make a semi-automatic system for visualisizng dimensions

semi-automatic dimensions visualisation system

One last thing I need is to make the text boxes automatically contain the wireframe cube's X, Y and Z dimensions (not scale) with units and 2 decimal point precision like this:

2.56 cm 7.2 mm 10 m

unfa
  • 1,199
  • 15
  • 23
  • Is your question about how to set the text of a text object, or how to get the dimensions of an mesh object? – JakeD Sep 07 '16 at 15:58
  • 1
    One way to update text http://blender.stackexchange.com/a/6973/15543 To display units http://blender.stackexchange.com/a/1071/15543. – batFINGER Sep 08 '16 at 10:34
  • pycoder - my question is about how to get the dimensions, express them in human-readable form and write them automatically to text objects when the "bounding box" object changes dimensions. – unfa Oct 11 '16 at 07:36

1 Answers1

2
#ob is the object you want to measure
#x_ob,y_ob,z_ob are the three text objects
(x,y,z) = ob.dimensions.to_tuple()
x_ob.data.body = str(x)
y_ob.data.body = str(y)
z_ob.data.body = str(z)

If you want to use the metric system, you can add this:

bpy.context.space_data.context = 'SCENE'
bpy.context.scene.system = 'METRIC'

If you want the correct unit you can make this kind of function:

def units(x):
    if int(x) > 0:
        u = "m"
        y = x
    elif x*100 > 0:
        u = "cm"
        y = x*100
    else:
        u = "mm"
        y = x*1000
    return str(y)+" "+u
Vanitat
  • 281
  • 3
  • 7