View Full Version : simple proc gives error


jgibz
09 September 2005, 09:42 PM
Hi everyone, I have this proceedure that takes two objects, and moves the first to the position of the second.

proc MoveToObject(string $moved, string $to)
{
vector $positionTo = `getAttr $to.translate`;

select $moved;

move ($positionTo.x) ($positionTo.y) ($positionTo.z);

select -cl;
}

When passing two strings, each containing the name of a sphere in the scene....

MoveToObject($sphereOne, $sphereTwo);
// Error: No object matches name: .translate //

Any help would be great:)

JFFORTIN
09 September 2005, 12:15 AM
proc MoveToObject(string $moved, string $to)

{

float $positionTos[] = `getAttr ($to + ".translate")`;

select $moved;

move $positionTos[0] $positionTos[1] $positionTos[2];

select -cl;

}

jgibz
09 September 2005, 05:45 PM
thanks JFFORTIN, Is there a bonus to using an array to store the attributes as opposed to a vector in this instance? I guess it would be better to use one array instead of 3 vectors if I were storing values for trans, rotate and scale.

Segmoria
09 September 2005, 03:22 PM
I believe you can't store data to a vector using the form:
vector $positionTo = `getAttr $to.translate`
You can only use the form vector $vect = <<1, 2, 3>> but you always have to make sure you are using scalars numerics only.
Nor you can say $positionTo.x = `getAttr $to.translateX`;

Instead you have to do the following:
float $temp = `getAttr $to.translateX`;
$positionTo.x = $temp;

As for the array advantages, when using arrays in MEL, the array subscript is being incremented as you add more data into it (thats why you don't have to define their size when declaring an array). And you can always use arrays of vectors if you wish so.

jgibz
09 September 2005, 01:25 PM
vector $position = `getAttr ($to + ".translate")`;

works as well,
Thanks for the info.

CGTalk Moderation
09 September 2005, 01:25 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.


1