View Full Version : Length of an edge?

12-15-2007, 11:46 PM
Is there a command that would allow me to determine to length of an edge in maya units? Or perhaps someone could point me in the right direction... I'm looking to make a script that basically allows me to select an edge and it'll return the length immediately.



el diablo
12-16-2007, 08:39 AM
you can convert it to a curve and do an arclen on the curve....el_diablo

12-16-2007, 10:59 AM
having 2 points A and B, the distance between them is:
sqrt( (xA-xB)^2 + (yA-yB)^2 + (zA-zB)^2 )

so, get the coords of the points forming the edge (`xform -q -ws -tr` returns
them directly if you select an edge) and use the formula.

if you want to do it for an edge loop, you could do it the same way for
every edge, but i'm sure there are also faster, approximating, ways.

12-19-2007, 07:55 PM
sorry, dubbleposting

12-19-2007, 08:09 PM
this ain't pretty but it does return an endgelength based upon two selected vertices....
note, i'm not a scripter so this scriptie's not realy efficient'n stuff

proc float getDistance() {
float $delta[];
float $v1[3];
float $v2[3];
string $vertices[];
$vertices = `filterExpand -sm 31`;
vector $magVector;
float $distance;

if (`size $vertices` == 2) {
$v1 = `pointPosition $vertices[0]`;
$v2 = `pointPosition $vertices[1]`;

for ( $i = 0; $i < 3; $i++ ){
$delta[$i] = $v1[$i] - $v2[$i];
$magVector = $delta;
$distance = `mag $magVector`;
} else {
$distance = 0;
return $distance;

12-20-2007, 11:22 AM
@el diablo: hehe :] good one!
@cpan: thats right!
@shi76a: you scripted this? mag to get the length is a good way too!!

look I rounded it up a little:
proc float getDistance()
string $vertices[] = ls("-fl", polyListComponentConversion("-tv"));

if (size($vertices) == 2)
float $v1[] = `pointPosition $vertices[0]`;
float $v2[] = `pointPosition $vertices[1]`;

return mag(<<$v1[0] - $v2[0], $v1[1] - $v2[1], $v1[2] - $v2[2]>>);

return 0;
}No need for all those variables. And you can just convert the selection to vertices ("-tv"). Making you able to just select an edge and there you go.

12-22-2007, 06:52 PM
thanks for cleaning it up :) its much clearer now :)

12-24-2007, 05:52 PM
There's also an edge length HUD in the Bonus Tools.

12-28-2007, 04:47 PM
thanx a lot guys...will try

CGTalk Moderation
12-28-2007, 04:47 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.