PDA

View Full Version : Declare variable name from another variable?


H2o-KiD
11-26-2011, 01:34 PM
Hi guys, it's me again! (still a noob :blush: )

Something like this maybe? Is this possible?

for ($c = 0; $c < 10; $c++)
{
string $myVar#[] = {}; //# from $c, is it possible?
}

H2o-KiD
11-26-2011, 03:35 PM
or... array within array?

NaughtyNathan
11-26-2011, 07:43 PM
no, and no.

MEL doesn't support 2D arrays, so if you want an array in an array you'll need to use the stringToStringArray and stringArrayToString MEL functions to compile and decompile arrays into a strings and then just store those in string arrays (and vice versa).
polyCube;polyCube;polyCube;polyCone;polyCone;polyCone;polyCone;polySphere;
string $wilds[] = { "pCube*" , "pCone*" , "pSphere*" };
string $arrayArray[] = {};
for ($item in $wilds)
{
string $temp[] = `ls -type "mesh" $item`;
$arrayArray[size($arrayArray)] = `stringArrayToString $temp ";"`;
}
print $arrayArray;



Alternatively, switch to python as the list (array) capabilities of python are mind-blowing in comparison to MEL.

:nathaN

thasanty
11-27-2011, 11:58 PM
It is possible to declare a variable from another variable, at least in Python(you should really begin migrating!), here the code to do so:

for i in range(10):
exec("myVar{0} = list()".format(i))

for i in range(10):
exec("print myVar{0}".format(i))

Hi guys, it's me again! (still a noob :blush: )

Something like this maybe? Is this possible?

for ($c = 0; $c < 10; $c++)
{
string $myVar#[] = {}; //# from $c, is it possible?
}

CGTalk Moderation
11-27-2011, 11:59 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.