View Full Version : Syntax: Accessing Vector Array Components

06 June 2007, 02:46 PM

How can i access the Component Values of a Vector when the Vector is an Array?

vector $DestTrl[];
setAttr ($SourceObj[$i] + ".tz") ($DestTrl[$i].x); // Syntax error //

At the moment a have a workaround by copying the values temporally out of the Array.
Is there no direct access?


06 June 2007, 11:57 AM

You should try doing the concatination of the strings first in seperate variables, then query the value you need from the second tempory string, it uses more lines of code but the setAttr command wont have as many problems.

Remember the setAttr Command works

setAttr AtributeString Value ;

it appears your trying to do

setAttr AttributeString String;

you cant set a translation value with a string.

try the following method:

vector $DestTrl[];

string $temp1 = $SourceObj[$i] + ".tz"; //Concatinate the first string for the Attr name
string $temp2 = $DestTrl[$i] + ".x"; //Concatinate the second string for the Vector

float $Value = `getAttr $temp2`; //Query The Value and store it in a float variable

setAttr $temp1 $Value; //Set The attribute with the variable retrieved from the vector

Give it a try, i dont have Maya installed at the moment so i cant try it, but thats a method i use quite a lot when things seem not to work as you want. This way you can step through line by line and you can find your error easier than having one complex line of code.

Hope that helps


06 June 2007, 05:44 PM

vector $DestTrl[] is a float and not a string Array.

So I'm still doing " setAttr AtributeString Value ;"

As i said i'm casting my values temporally out of the vector array and it's working.

The Line i have written was just a try to explain what i'm after.
But i don't understand why there is no direct access to the components...

hmmm.....thxs anyway


06 June 2007, 06:17 AM
setAttr ($SourceObj[$i] + ".tz") ($DestTrl[$i].x); // Syntax error //

yeah that would happen. That $DestTrl[$i].x you have in there would call a vector not an array. You can try calling [0] instead of .x; except I can't see how you'll have a list set up with arrays as each object of the list. $DestTrl[$i]

If you are trying to call up the vector information of objects in an array, you are going to need to getAttr of the object before you can call the x value of the vector.

Unless I've just never work with vector arrays before, it seems like there would be a different way to do what you want to do but I don't know the rest of your code.

Uhhh upon further inspection try ($DestTrl[$i]+".x"); just thinking.

06 June 2007, 10:51 AM
very helpful: you can set up little functions for that:


06 June 2007, 11:22 AM
Thxs for the info...

CGTalk Moderation
06 June 2007, 11:22 AM
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.