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

02 February 2008, 12:42 PM
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 February 2008, 03: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.

02 February 2008, 06: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] + "']");

02 February 2008, 12:56 PM
wow, thanks alot Adrian ... I`ll give it a try. :)

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