View Full Version : how to store a string retunred from a proc into a new stringVar?

07 July 2012, 01:15 AM
so here's problem that my lowbudget Mel skills haven't been able to resolve.

I have a procedure that gives me the distance of 2 objects by simply creating a distance between node for 2 given objects. It also names the DB node as well. I have set it up to return a string value with the name of the DB node

I'd like to know how I could store the return value in string in order to use the string in other procedures.

The example below is the script as it stands, with a sample execution line. I've also written out the method I am trying to use to capture the returned string.

global proc string measure2Points (string $itemA, string $itemB, string $name)


string $dbNode = `createNode distanceBetween -n $name`;

connectAttr ($itemA + ".worldMatrix") ($dbNode + ".inMatrix1");
connectAttr ($itemB + ".worldMatrix") ($dbNode + ".inMatrix2");

connectAttr ($itemA + ".rotatePivotTranslate") ($dbNode + ".point1");
connectAttr ($itemB + ".rotatePivotTranslate") ($dbNode + ".point2");
return $dbNode;


//execute the command bellow and all works fine...
measure2Points ("pSphere1","pSphere2" ,"distBet_sphere1tosphere2");

//But, when I need to call the 'distance between' node itself, a syntax error is registered

string $dbName = `measure2Points ("locator4", "locator5", "db_locs")`;
// Error: Syntax error //

07 July 2012, 02:29 AM
Try it this way instead -
string $dbName = `measure2Points "locator4" "locator5" "db_locs"`;

07 July 2012, 08:40 AM
thanks very much, that worked perfecly.

...and it sort of makes sense, I see how it shares simmilarites with a standard maya command, so you lose the brackets and commas and just double quote the arguments.

thanks again

07 July 2012, 02:50 PM
Your original syntax would have worked if you left out the back-quotes. Sometimes its actually better to do it this way.

string $dbName = measure2Points ("locator4", "locator5", "db_locs");

Now you know both though.


07 July 2012, 05:10 PM
thanks David,

That's a great help.


CGTalk Moderation
07 July 2012, 05:11 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.