PDA

View Full Version : Loopity loops...


jjburton
07-14-2008, 04:03 PM
This is probably a basic q, I'm not a programmer. What I'm trying to do is run some "for loops" on the content of several string arrays . i.e. for each object in each object set do that.

My first thought was to parse the array names into another array and run a for loop on that. However, I couldn't get it work.


string $baseObjectSets[] = {"$qssBaseObjects0","$qssBaseObjects1"};
string $qssBaseObjects0[] = {"pCube1", "pCube3"};
string $qssBaseObjects1[] = {"pCube1", "pCylinder3"};


for ($set in $baseObjectSets) {
string $objectSet = $set;
for($object in $objectSet) {

}


I've tried a couple of methods but nothing seems to work. The $object will print as the correct name but the second for loop errors out saying it's not an array.

Any help would be appreciated:)

Buexe
07-14-2008, 05:16 PM
string $objectSet = $set;

defines a string not an array of strings, the "[]" are missing, but even if on the right hand side is only a string so Maya will complain again. You should provide another array if you want to loop over that. for example query the members of a set and then do something with them, like



string $baseObjectSets[] = {"$qssBaseObjects0","$qssBaseObjects1"};
for ($set in $baseObjectSets) {
string $objectSet[] = `sets -q $set`;
for($object in $objectSet) {
print ( $object + " is a member of " + $set + "\n");
}
}


hope this helps...

jjburton
07-14-2008, 08:28 PM
Buexe, thanks for the help. However, for some reason it won't recognize that "qssBaseObjects0" exists when used in that format. I think it's because the "sets" command is looking to query and actual set and not an array.

Is there a similar command to query the members of an array?

Buexe
07-14-2008, 08:41 PM
well, it was just an example, of course you have to fill in your stuff, maybe this loop-style fits your purposes better, of course it can be combined with other loops

string $qssBaseObjects0[] = {"pCube1", "pCube3"};
for ( $no = 0 ; $no < size ($qssBaseObjects0); $no++)
{
print ("Here you go: " + $qssBaseObjects0[$no] + "\n");
}

jjburton
07-14-2008, 10:39 PM
Buexe, I discovered with further research and a buddy's instruction that what I was trying wasn't possible and was a programming no no. However, I'm working on another avenue.

Thanks again:)

ewerybody
07-15-2008, 10:10 AM
hehe :] you tried to put an array into an array!! :D
Thats not possible with mel! But what you could do is append an array to another one!

I use a method where i create a new array in the following style:
NrOfIndices1, Array1_1, Array1_2, Array1_3, NrOfIndices2, Array2_1, Array2_2 ...
or literally:
{2, "object1_1", "object1_2", 3, "object2_1", "object2_2", "object2_3", 1, "object3_1", 5, "object4_1" ... }
question is if you really need that.. 2d-arrays is no problem for python I heard. *shrug*

CGTalk Moderation
07-15-2008, 10:10 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.