Tuesday, November 30, 2010

Mel : How to return multiple values in procedure?

you can do this using string array

global proc string[] myproc() {
    string $r[];
    string $sel[] = `ls -sl`;
    float $pos[] = `xform -q -ws -t $sel[0]`;
    $r[0] = $sel[0];
    $r[1] = $pos[0];
    $r[2] = $pos[1];
    $r[3] = $pos[2];
   
    return $r;
}


myproc();


so for example if you want to store selected object's transform node and shape node name along with translate x,y,z in a string array, you can plug all of them in string array inside the proc.
here i am forcing my script to store values only if shape node is camera.

global proc string[] camtr(string $myselection[]) {
    string $return[];
    string $shp[] = `listRelatives -s $myselection[0]`;
                for ( $s in $shp )
                {
                string $cam = `nodeType $s`;
                    if ($cam == "camera")
                    {
                    print ( "\n YES " + $s + " is camera\n");
                    $pos =`xform -q -ws -t $myselection[0]`;
                    $return[0] = $myselection[0];
                    $return[1] = $shp[0];
                    $return[2] = $pos[0];
                    $return[3] = $pos[1];
                    $return[4] = $pos[2];
                    }
                    else
                    {
                    print ( "\n No " + $s + " is not a camera. It is a " + $cam +"\n");
                    }
            }

    return $return;
}

  
to see result of above proc

string $sel[] = `ls -sl -fl`;
string $b[] =camtr($sel);

4 comments:

Pawel Swierczynski said...

Thanks for the tip! :)

antoine vandevoorde said...

thanks ! very useful !

antoine vandevoorde said...
This comment has been removed by the author.
uraniyabacon said...

Casino de Reno
The only place to play blackjack with no cash is at Harrah's 망고 도매인 Casino. At most sss 포커 table games 슬롯머신 무료 like Texas Hold'em or Omaha Hi-Lo 꽁 머니 토토 사이트 Omaha, it's hard to see why 온라인 슬롯 사이트 you

Integration/Tracking Demo Reel 2018 on Youtube