PDA

View Full Version : Getting Transforms from a list of selected


cwisbg
11-23-2011, 11:03 PM
So im just trying to get transforms from one object, store them, and then apply them to another object.
So far i have the getting atributes from one object with-

string $Tree[] = `ls -sl`;



for($i =0; $i < size($Tree); $i++){ // ( this is ment to, in my mind, cycle thought the array and do //the following opporations to every thing. not sure if this is right please correct me )


float $rx = `getAttr $Tree.rx`;
float $ry = `getAttr $Tree.ry`;
float $rz = `getAttr $Tree.rz`;
vector $attrs = << $rx, $ry, $rz>>;
print $attrs;
}



this works for getting the attributs from one object selected, but when i try two objects it returns
// Error: Cannot convert data of type float[] to type float. //

and i dont know what it even mean or how to fix it ...help would be much appreciated

WesHowe
11-24-2011, 01:02 AM
Fix this:
float $rx = `getAttr $Tree[$i].rx`;
(also change the .ry and .rz lines).

Your $Tree[] variable needs to be consistently used as an array.

<* Wes *>

NaughtyNathan
11-24-2011, 07:58 PM
if you only want to iterate over the items in an array, use this method:
string $array[] = `someArray`;
for ($item in $array)
{
doFunction $item;
}you only need to use the other type of for..loop if you need counters or indices. for example starting from a given index or stepped or backwards iteration.
string $array[] = `someArray`;
for ($n=0 ; $n<size($array) ; $n++)
{
doFunction $array[$n];
}additionally, don't bother working with individual vector components unless you actually want the individual components:
string $trees[] = `ls -sl`;
for($item in $trees)
{
vector $rot = `getAttr ($item + ".r")`;
print ($rot + "\n");
}or:string $trees[] = `ls -sl`;
for($t=0 ; $t<size($trees) ; $t++)
{
vector $rot = `getAttr ($trees[$t] + ".r")`;
print ($rot + "\n");
}:nathaN

CGTalk Moderation
11-24-2011, 07:58 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.