PDA

View Full Version : create string arrays within for-loop ?!


Inlakechh
02-20-2008, 11:42 AM
Hey guys, I'm stuck with a little Mel syntax problem.
I`m trying to create an array with a different name each time the calculation goes through a for-loop.


for ($ii=0;$ii<`size $lights`;$ii++)
{
string (&quot;$light_&quot;+$ii+&quot;[]&quot;) = `lightlink -query -light $lights[$ii]`
}


it's not putting the number into the $ii variable.
Please give me a hint on how to write it correctly.

Thank you alot in advance.

Robert Bateman
02-20-2008, 02:19 PM
You'd need to generate the variable declaration then chuck it at eval. Be warned though, to make this work you'll need to declare them all global - which is a fairly bad idea imho.

greatPumpkin
02-21-2008, 05:32 PM
you could store the variables in a python dictionary instead:

python("import maya.cmds as mc");
string $lights[] = `ls -type "light"`;
for($light in $lights)
{ python ("import maya.cmds as mc");
python ("linkQuery = {}");
for($light in $lights)
{ python("linkQuery['" + $light + "'] = mc.lightlink('" + $light + "',q=True)");
}
}

// then to access links for a specific light:
string $links[] = python("linkQuery['" + $lights[0] + "']");

Inlakechh
02-23-2008, 11:56 AM
wow, thanks alot Adrian ... I`ll give it a try. :)

CGTalk Moderation
02-23-2008, 11:56 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.