Monday, March 15, 2010

Mel: Measure Distance

Maya has this Measure tool which pretty much does the job but i always felt lazy to go thru Create Menu / Measure tool and click on vertices one after other with snap on. too many things to do to get simple distance between two points. i made this script handy for myself for quick checks specially when i have survey information and measurement from set. you can simply make this global procedure in your user/maya/script path and assign hotkey to even make it quicker. it saves time when you want to query lots of measurements and cross check track data scale from tracking software in 3D. pretty sure this can be handy even for modelers, animator and fx guys. script currently works for transform, mesh, nurbsCurve type of nodes. you can modify it further to include different nodes based on your needs.

script is self explanatory. also if you have any suggestion to make this script better please share.

global proc getdistance(){

string $currentsel[] = `ls -sl -fl`;
if ($currentsel[0] == "") error "You must select two nodes or vertex to measure the distance";
else {

int $numofvertex = size($currentsel);

if($numofvertex > 2) error "More than 2 nodes selected. Make selection again with only two nodes to measure distance between them";
else {
if(`objectType -isType "mesh" $currentsel[0]` || `objectType -isType "nurbsCurve" $currentsel[0]`)
{

vector $va = `pointPosition $currentsel[0]`;
vector $vb = `pointPosition $currentsel[1]`;
vector $distpos = $va - $vb;
float $d = `mag <<$distpos.x, $distpos.y, $distpos.z>>`;
string $unit= `currentUnit -query -linear`;
print ($d + "\t" + $unit);

}
else if (`objectType -isType "transform" $currentsel[0]`)
{

vector $va = `xform -q -ws -a -rp $currentsel[0]`;
vector $vb = `xform -q -ws -a -rp $currentsel[1]`;
vector $distpos = $va - $vb;
float $d = `mag <<$distpos.x, $distpos.y, $distpos.z>>`;
string $unit= `currentUnit -query -linear`;
print ($d + "\t" + $unit);

}

}
}



}

No comments:

Integration/Tracking Demo Reel 2018 on Youtube