PDA

View Full Version : Syntax: Accessing Vector Array Components


GiantG
06-15-2007, 03:46 PM
Hi.

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

Example:
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?


Thxs.

Spireite
06-16-2007, 12:57 PM
Hey,

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

Spireite

GiantG
06-17-2007, 06:44 PM
Hi.

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


Greetz

trancor
06-18-2007, 07:17 AM
[QUOTE=GiantG]
setAttr ($SourceObj[$i] + ".tz") ($DestTrl[$i].x); // Syntax error //
QUOTE]

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.

ewerybody
06-19-2007, 11:51 AM
very helpful: you can set up little functions for that:

see: http://www.highend3d.com/boards/index.php?s=&showtopic=213754&view=findpost&p=215713

GiantG
06-19-2007, 12:22 PM
Thxs for the info...

CGTalk Moderation
06-19-2007, 12:22 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.