MEL for measuring a distance?(auto-rigging)


#1

I am working on a Script for automating the rigging process and have become stuck on how to measure a distance in 3d using MEL.

I have a locator at the origin, (baseLocator) and one that the user must place at the top of the character’s head (heightLocator). Doing this by hand I would use the measure tool, and the MEL for that is ‘distanceDimension’. The flags for distanceDimension are -startPoint and -endPoint, which each expect 3 linear numeric values.

The Code so far:
string $baseNode[] = listRelatives -shapes "baseLocator";
string $heightNode[] = listRelatives -shapes "heightLocator";
float $baseVec[] = spaceLocator -query -position $baseNode[0];
float $heightVec[] = spaceLocator -query -position $heightNode[0];
string $dist = distanceDimension -startPoint ($baseVec[0]) ($baseVec[1]) ($baseVec[2]) -endPoint ($heightVec[0]) ($heightVec[1]) ($heightVec[2]);

string $dShapes[] = listRelatives -parent $dist;
rename $dShapes[0] myDistance;
float $charHeight = getAttr myDistanceShape1.distance;
float $scaleFactor = ($charHeight / 179.485);

I start getting errors on the 3rd Line, "Cannot convert data of type string to type float[]. // "
How can I get the spatial coordinates of the locators into the distanceDimension command?

I want to do another script that measures a distance in 3d space and then evenly divides it placing joints evenly for the spine. I need to figure this out first though…
I truly appreciate any MEL experts out there being able to explain this to me.
Thank you!


#2

Could you not try using getAttr(item.translateX)? There’s probably a way to get all three in one command, but at least you can get all of them if you query for all three axis.


#3

You could shorten this script:

vector $a = `xform -q -ws -t "baseLocator"`;
vector $b = `xform -q -ws -t "heightLocator"`;
float $charHeight = mag($a - $b);
float $scaleFactor = ($charHeight / 179.485);

#4

Thank you for the replies!

Yes, Zaskar, your code works perfectly! Also much more brief and elegant than what I was thinking. Posting on this forum really helped me out, Thanks!

I will continue coding and hopefully I will immediately come up with such good solutions in the future when I have more experience…