How do you measure distances in Blender?

I need to do some very accurate modeling but I can’t find any measuring tools in Blender.

I want to be able to measure between two points in space and get the difference in the X,Y and Z planes as well as the absolute distance.

Is Blender capable of this or must I use a proprietry 3D CAD package instead? :frowning:

Thanks
Paul

There’s no way to do it with the built-in tools, but it’s fairly easy to do it with a little python script. Don’t know if anyone has published such a script though… It’s a trivial programming effort.

Hmmm … it’s a pity it’s not built in.
I really don’t have the energy to learn Python scripting and how the plugin interface works.

It’s something that should be added to the wishlist since it’s useful and should be trivial to code into blender.

Paul

It wouldn’t be useful to the very vast majority of Blender users I feel.
I too need precision in my drawing but being a cabinetmaker 1/32nd of an inch is about enough.
I have no problem attaining that kind of precision using a series of screens that I set by default (ctrl+u) in all my files. Each has the grid set to its own unit, may it be ‘one foot per blender unit’,
‘one inch per…’, 1/2, 1/4, !/8th and so on

With some ingeniosity and experience it becomes easy but it certainly isn’t obvious from the start.

If you place empties at the two points of which you would like to know the distance, you could execute(alt-p in the textwindow)the following script:


from Blender import *
from math import *

loc1 = Object.Get("Empty")
loc2 = Object.Get("Empty.001")

dlocx = loc2.LocX - loc1.LocX
dlocy = loc2.LocY - loc1.LocY
dlocz = loc2.LocZ - loc1.LocZ

distance = sqrt((dlocx)**2 + (dlocy)**2 + (dlocz)**2)

print dlocx, dlocy, dlocz, distance

the results are returned in the dos window, the first three are the distances in the x, y and z direction, and the last number is the distance between the two points.

There are probably better ways to do this, but I hope it helps

greets,

wim

Thanks, I’ll give it a try as soon as I’ve figured out what you mean by "Empty"s.
I’ve used 3D Studio Max 3 and 4 but I’m new to Blender.

Paul

You’ll find the empty(ies) next to the lamps, cameras, armatures in the dialog that appears when the space bar or shift+a are pressed.

They are objects that can’t show in the final render. So they can’t be linked to a material/texture but otherwise you can size them, move them rotate them, animater them and the rest.
Among other uses (and they’re very useful!) they are place holders ; sometimes you can set, resize, animate another object’s texture using them ; they’re useful in animation, especially those of armatures…

Not so empty aren’t they ?

Hi

Selecting an object (turns pink) and pressing ‘N’ brings up a popup window with the position of the purple center spot (and other data).

In edit mode (TAB key) select a vertex (right click on vertex) and press ‘N’.
The popup window will give you the X,Y,Z coords of the vertex RELATIVE TO THE OBJECTS ORIGIN (Sorry about the shouting but its an easy thing to miss :-? ).

so vertex position = object position + vertex values.

All my modeling is for exporting from blender so I ensure all objects are centered on the origin anyway.

CHeers Stephen

that’s only true if there’s no scaling or rotation on the object itself.

If there is, it’s actually a little more complicated to calculate.


Vertice local position
V = 
      [x]
      [y]
      [z]

rotation and scaling matrix of the object
M = 
      [SizeX * cos(RotY) * cos(RotZ), 
            SizeY * (sin(RotX) * sin(RotY) * cos(RotZ) - cos(RotX) * sin(RotZ)), 
                  SizeZ * (cos(RotX) * sin(RotY) * cos(RotZ) + sin(RotX) * sin(RotZ))]
      [SizeX * sin(RotZ) * cos(RotY), 
            SizeY * (sin(RotX) * sin(RotY) * sin(RotZ) + cos(RotX) * cos(RotZ)), 
            SizeZ * (cos(RotX) * sin(RotY) * sin(RotZ) - sin(RotX) * cos(RotZ))]
      [SizeX * -1 * sin(RotY), 
            SizeY * sin(RotX) * cos(RotY), 
                  SizeZ * cos(RotX) * cos(RotY)]

global coordinates of the vertex
Vg = M * V

a little more complicated…

Martin

But if you’re only interested in the distances you just need to use the object’s scaling factor, you don’t need Loc or Rot.
If you want to be really accurate you can actually move the individual points around in the ‘N’ window, it’s tedious, but extremely accurate, I use it all the time for modelling structures and the like where i know what the dimensions are meant to be.

I stand corrected :expressionless:

Thanks for posting the vertex position code. Who (originally) wrote it, and could I adapt it (appropriately credited) to use in an export script please?

I’ve been trying to work it out for a while. I have been trying a different method that appears to only cope with rotation around one axis.

Cheers Stephen

it’s a standard rotation matrix for Linear Transformation theories, so if you want to thank whoever first wrote this, I guess you’d have to dig a 19th century corpse… :stuck_out_tongue:

If you need some help with vectorial and matricial operations, there’s a python module made mostly by eeshlo (but I helped a little :wink: ) that handles that. Just ask me and I’ll e-mail it to you.

Martin

I modified the distance script from tuinbels a bit.
Just make a .py file (e.g distance.py) out of it and copy it into your ~/.blender/scritps directory (executeable)
It should be available in the “Object” menu under “Scripts” after a blender restart.

#!BPY
#####################################################################
# blender_distance.py
#   This script calculates the distance vector and the distance
#   itself between two objects (measured from the basepoint i hope)
#   in Blender.
#
#   (c) Basic functions by tuinbels under
#       https://blenderartists.org/forum/viewtopic.php?p=82923#82923
#   Modified and extended by Martin (Pontiac) Buerbaum
#
#   The script is currently VERY basic, but if anybody has some
#   spare time he is free to modify it.
#   
#   License:
#     The content of this file is under the GNU/GPL license.
#     http://www.gnu.org/licenses/gpl.txt
#####################################################################

""" Registration info for Blender menus: <- these words are ignored
Name: 'Distance'
Blender: 235
Group: 'Object'
Tip: 'Calculate the distance between two objects.'
"""

__author__ = "Martin (Pontiac) Buerbaum"
__url__ = ("blender", "elysiun",
"Script's thread in elysiun forum, https://blenderartists.org/forum/viewtopic.php?t=10318")
__version__ = "0.0.2"

import Blender
from Blender import *

import math
from math import *

#import sys


print "<<< Distance calculations >>>"
selected_objects = Object.GetSelected()

if len(selected_objects) >= 2:
	dlocx = selected_objects[1].LocX - selected_objects[0].LocX
	dlocy = selected_objects[1].LocY - selected_objects[0].LocY
	dlocz = selected_objects[1].LocZ - selected_objects[0].LocZ

	distance = sqrt((dlocx)**2 + (dlocy)**2 + (dlocz)**2)
	
	Blender.Window.WaitCursor(0)
	outputtext = "(dX, dY, dZ); Distance|(%f,%f,%f); %f" % (dlocx, dlocy, dlocz, distance)
	Blender.Draw.PupMenu(outputtext)
	print outputtext
else:	
	text_notenoughobjs = "Error!|Not enough objects selected"
	Blender.Window.WaitCursor(0)
	Blender.Draw.PupMenu(text_notenoughobjs)
	print text_notenoughobjs

Does anybody know how to get to the selected vertices/edges from python scripts? That would be quite handy and even easier to use.

Comments and especially improvements welcome :smiley:
Pontiac

Yup…lookie here: http://www.blender.org/modules/documentation/236PythonDoc/NMesh.NMVert-class.html

the mesh is updated when you leave edit mode, so if you are edit mode, leave. you can do that via script with Window.EditMode.

from there, just loop through all of the verts and if it’s selected, keep it.