one to one constrain in nested loops


#1

hi,

Actually i’am trying to write mel script but i stucked at one place basically there is two textScrollList’s in my code one for animation control’s and one for objects like polygon, joints, locators etc. what i want to do is i want to constrain these objects to those controls but how can i constrain one to one in those list’s like 1st control to 1st object and so on. i can get any one list in the array but not two and this is my last step in my script please help…

thank you…


#2

Here is the code finally i actually achieved so this is not actual code but it is an example how to get two arrays or more. i hope this might help anybody…

string $list1[] = {"a", "b", "c"};
string $list2[] = {"1", "2", "3"};

//take any one of your variable to know the size of list...
for ($i=0; $i<size($list1); $i++){
    string $items1[];
    string $items2[];
    
    //now come to the actual loop...
    for ($array1 in $list1){
        $items1[$i] = $list1[$i];
        }
    for ($array1 in $list2){
        $items2[$i] = $list2[$i];
        }
    
    print ("value of " + $items1[$i] + ": " + $items2[$i] + "
");
    }

thank you.


#3

Maybe I missed the point, but why not just do this?..

string $list1[] = {"a", "b", "c"};
string $list2[] = {"1", "2", "3"};

//take any one of your variable to know the size of list...
for ($i=0; $i<size($list1); $i++){
    print ("value of " + $list1[$i] + ": " + $list2[$i] + "
");
}

David


#4

hello djx,

Please see my question you will know what i am trying to achieve your code works for printing statements but might not be for constraining one object to another for example i had 10 objects and 10 controls so i want to constrain 1st control to 1st object and 2nd control to 2nd object so on… but what i have posted is working exactly what i want to achieve but there may be other option. hope this understands…


#5

I meant that in your example you seem to be doing two loops for no reason.
If you have two textScrollLists then you can simply use the -allItems flag to get the arrays.


string $TSL1 = `textScrollList etc etc`; 
string $TSL2 = `tectScrollList blah blah`;
int $numItems = `$TSL1 -q -ni`;
string $list1[] = `$TSL1 -q -allItems`;
string $list2[] = `$TSL2 -q -allItems`;

for ($i=0; $i<$numItems; $i++){
    print ("value of " + $list1[$i] + ": " + $list2[$i] + "
");
}

David


#6

hello djx you are right. i don’t know why my mind got that thought after thinking long time anyway thanx for your code…