1
$\begingroup$

I realized I left out a few details and overcomplicated this. I'm working in inches which only has 1 decimal place in the dimensions tab and I'm trying to add more decimal places.

I'm trying to get precise outer dimensions of multiple objects in a scene (they need to be exact). I've tried measure it but it takes to long to get the length of just one side. It would be fastest if I could just click the object and read off all 3xyz like under the transform tab. But it only gives me 1 decimal place and I'm working in 4. Both X and Y are the same dimension in the picture but I have to click on each one to get the entire dimension of it. Is there some way to increase the precision? enter image description here

$\endgroup$
2

1 Answer 1

1
$\begingroup$

You can have a look at the Scene, Units panel in the Properties Editor to choose different unit:

enter image description here

Alternatively, you can add a panel with that information to the Sidebar with Python:

import bpy


class DimensionsPanel(bpy.types.Panel):
    """Creates a dimensions panel in the Sidebar"""
    bl_label = "Dimensions"
    bl_idname = "OBJECT_PT_dimensions"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Item"

    def draw(self, context):
        layout = self.layout
        obj = context.object
        to_str = bpy.utils.units.to_string
        
        col = layout.column()
        col.label(text="X: " + to_str('IMPERIAL', 'LENGTH', obj.dimensions.x, precision=7))
        col.label(text="Y: " + to_str('IMPERIAL', 'LENGTH', obj.dimensions.y, precision=7))
        col.label(text="Z: " + to_str('IMPERIAL', 'LENGTH', obj.dimensions.z, precision=7))

def register():
    bpy.utils.register_class(DimensionsPanel)


def unregister():
    bpy.utils.unregister_class(DimensionsPanel)


if __name__ == "__main__":
    register()

enter image description here

As you can see I use bpy.utils.units.to_string function from Blender's API. You could modify that.

You said, you want to read the values, so labels will give you that, you would need to make properties if you wanted to select and copy them, but you can also output that info straight to something else with Python like a text file, Blender's text block, or whatever else is possible with Python(so pretty much anything). In that case writing an operator would be better. See Text Editor's Templates menu for examples of how to do that or make this an add-on so you don't need to run it from the Text Editor every time. Or just ask another more specific question.

Also note that we are close to the precision limits of 32bit floats and binary precision issues do exist.

$\endgroup$
4
  • $\begingroup$ This is exactly what I was looking for. But after toying around with it a bit (I don't know much python) the imperial only does feet. Or is it possible to have it to inches? $\endgroup$
    – Hackshop
    Jan 2 at 1:41
  • $\begingroup$ @Hackshop, Blender's unit conversion is sort of smart and will display more or less appropriate units depending on the size of the values, you could use split_unit=True after precision value(see the docs) in the function to split the units or it would be possible to just use simple math to convert units yourself. If you chose to convert units yourself, precision issues might become more relevant. 32bit floats are precise to about 7 decimals. This means 3.141592 is OK, so is 314.1592, but if you want to store 1003.141592 in 32 bit float, you have a problem $\endgroup$ Jan 2 at 1:52
  • $\begingroup$ The modeling I'm doing wont ever put me past 6 digits so I shouldn't have any precision issues and if it ever wavers a few hundred thou that will be fine. The split unit worked. it gave me the inches even though it did keep the feet which I can make do with. Thank you ill definitly take a closer look at blender's python $\endgroup$
    – Hackshop
    Jan 2 at 2:09
  • $\begingroup$ It's still worth keeping in mind precision errors are possible. It's also internally in Blender units that is meters unless you change unit scale so you might have precision issues when representing the values in another units. It's worth considering what is going on during conversion if precision is important. This is why most CAD software uses 64bit floats. Just be careful. It might also make sense to change unit scale in some circumstances to deal with this if you start encountering issues. Changing unit scale would require resizing any existing scene manually. $\endgroup$ Jan 2 at 2:36

You must log in to answer this question.

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