PDA

View Full Version : How to transfer array between procedures?


johnchuang
11-30-2007, 01:28 PM
Hi,guys.I'm new to mel.I want to use mel to accelerate my rigging process. I have a question about transfer array between procedures.

let's say:


//--------------------------------------------------------------------

//store all selected objects in array $temp;
string $temp[] = `ls -sl`;
.....

global proc a()
{
.......
//how can I use $temp[] here?

.......
}

global proc b()
{
.......
//and here?

.......
}

//--------------------------------------------------------------------




or :

//--------------------------------------------------------------------

global proc a()
{
.......
//store all selected objects in array $Atemp;
string $Atemp[] = `ls -sl`;

.......
}


global proc a()
{
.......
// Is that possible to use $Atemp[] here?

.......
}




//--------------------------------------------------------------------


any help will be greatly appreciated!!!

goleafsgo
11-30-2007, 02:10 PM
You could get the array somehow in one proc and then pass it to the other proc so they both work on the same array.

global proc procA()
{
string $sel[] = `ls -sl`;
...
procB($sel);
}

global proc procB(string $arr[])
{
...do something with $arr here...
}

Norb
11-30-2007, 06:20 PM
or another way you could do it is something like this:


global proc string[] selectItems()
{
string $sel[] = `ls -sl`;
return $sel;
}

global proc doStuff()
{
string $selection[] = `selectItems`;
for ($obj in $selection)
{
print ("\n"+$obj);
}
}


what is happening is that whenever the procedure selectItems is called, it returns a string array (you could specify any variable type in there). The return command populates that array with the value dictated inside the procedure.

when 'doStuff' is called, it fills the $selection variable with the array returned by selectItems and then you can do stuff to the objects in that array.

johnchuang
12-01-2007, 03:43 AM
Hi,Tim and Norb, Thank you very much !!! I figure it out . Both methods works well, personally I prefer the "return array" one.
Thank you guys ,you really help me out!!:thumbsup:

CGTalk Moderation
12-01-2007, 03:43 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.