PDA

View Full Version : Creating a separate list in another global proc.


JockeP
10-11-2009, 11:19 AM
Hi everyone.

Im writing a script where I want to store every newly created object in a list so that I can run another script on those items when the whole script is done.

I can create a a list within the global proc that is running, but it feels like Im using to much code and it gets dirty.
I want to call another global proc(or something alike) that runs this small code and stores the information in a list that the first proc can call on later.

The problem I have is getting the information back to the first proc from the second.
I tried using a textScrollList in the UI to store the list, but I get the message that procs cant be nested when I tried that solution.

So basicly I want to run this code in a separate proc:
string $nwObj[];
int $nwObjSze;
string $cSel[];
$cSel =`ls -sl`;
$nwObjSze=size($nwObj);
$nwObj[$nwObjSze] = $cSel[0];
instead of running it after each created object.

Any ideas how to pull it off?

Mark-J
10-12-2009, 08:20 AM
Just return the list from the first proc into the second.


global proc string[] BuildtheList()
{
string $List[] = `ls -sl -l`;
return $List;
}

global proc UseTheList()
{
//fill the list from the first proc
string $List[] = `BuildtheList`;

//Now Do Somthing with it
}



Or, you could pass the list by reference. This method declares the list before you pass it into the proc. Because you're passing the same variable in as an arguement it gets used and filled inside the proc. This is call pass by reference and in Mel can only be done with arrays[].


//Declare the list
string $List[];

//Pass the list in as a reference arguement to be filled
global proc BuildTheList( string $List[])
{
$List = {"This", "is", "a", "test"};
}
print $List



Hope that helps

Mark

JockeP
10-12-2009, 07:43 PM
Hi there Mark, thanks for the reply.
I have tested both of the solution you posted.
When I tried the first one I only manged to get 1 object in the list, and always the last one. I think that the list in the second proc was rested every time I called on it.

This is the testcode I used. I had a joint with 2 children selected

go;

global proc go ()
{
BuildtheList;
pickWalk -d down;
BuildtheList;
pickWalk -d down;
BuildtheList;
string $nwObj[]=`BuildtheList`;
print $nwObj;
}



global proc string[] BuildtheList()
{
string $nwObj[];
int $nwObjSze;
string $cSel[]= `ls -sl`;;
$nwObjSze=size($nwObj);
$nwObj[$nwObjSze] = $cSel[0];
return $nwObj;
}
(Only returned joint3)

I managed to get it to work with the second solution though, I got some errors in the start until I realised I had to put in the string next to the call for the proc :D

same selection new code

go;

global proc go ()
{
string $nwObj[];
BuildtheList($nwObj);
pickWalk -d down;
BuildtheList($nwObj);
pickWalk -d down;
BuildtheList($nwObj);
print $nwObj;
}



global proc BuildtheList( string $nwObj[])
{
int $nwObjSze;
string $cSel[]= `ls -sl`;
$nwObjSze=size($nwObj);
$nwObj[$nwObjSze] = $cSel[0];
}
(Returned Joint1,Joint2,Joint3)

Thanks for the help Mark =)

CGTalk Moderation
10-12-2009, 07:43 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.