PDA

View Full Version : Camera Setup Script finished..ready for Crits


Grayth
10-25-2005, 01:23 PM
Thanks to everyone for all their help on my first script. I finished it. While it works I'm sure there are better ways to code it, but this is how i figured it out so far for my first script.

your comments are welcome.

global proc Procam()
{
//variable creation here
string $grp1 = "XYZ_Trans";
string $grp2 = "YRot_Pan";
string $grp3 = "XRot_Tilt";
string $grp4 = "ZRot_Roll";
string $winName = "ProCam";
string $camnode = "1NodeCam";
string $camnode2 = "2NodeCam";
string $camnode3 = "3NodeCam";
//window check
if(`window -exists $winName`)
deleteUI -window $winName;
windowPref -remove $winName;
//window creation Layout here
string $myWindow= `window -title "Pro Camera Setup"
-w 260 -h 185 -s 0 -mnb 0 -mxb 0
$winName`;
//Main window Controls
string $form = `formLayout -nd 260 myform`;
string $labl= `text -label "Camera Name"`;
string $cameraName = `textField -w 150 Newname`;
string $sep =`separator -st "single" -w 225 divider`;
string $checka = `checkBox -l $camnode onenode`;
string $checkb = `checkBox -l $camnode2 twonode`;
string $checkc = `checkBox -l $camnode3 threenode`;
string $butn = `button -label "Create Camera" -c "Values" mybutton`;
//embedded form layout here
string $newform =`frameLayout -l "Select Editable Nodes" -w 225 -h 65 -p myform
-la "top" -bs "etchedIn"
-cll 0 -cl 0 embedform`;
//child of embededform Controls
string $form1 =`formLayout -nd 225 -p embedform nodeform`;
string $check1 = `checkBox -l $grp1 xyztrans`;
string $check2 = `checkBox -l $grp2 yrot`;
string $check3 = `checkBox -l $grp3 xrot`;
string $check4 = `checkBox -l $grp4 zrot`;
//Layout for embeded form Controls here
formLayout -e -af $check1 "top" 8 nodeform;
formLayout -e -af $check1 "left" 15 nodeform;
formLayout -e -af $check2 "top" 24 nodeform;
formLayout -e -af $check2 "left" 15 nodeform;
formLayout -e -af $check3 "top" 8 nodeform;
formLayout -e -af $check3 "left" 135 nodeform;
formLayout -e -af $check4 "top" 24 nodeform;
formLayout -e -af $check4 "left" 135 nodeform;

//layout for main window Controls here
formLayout -e -af $labl "top" 10 myform;
formLayout -e -af $labl "left" 10 myform;
formLayout -e -af $cameraName "top" 7 myform;
formLayout -e -af $cameraName "left" 85 myform;
formLayout -e -af $checka "top" 35 myform;
formLayout -e -af $checka "left" 10 myform;
formLayout -e -af $checkb "top" 35 myform;
formLayout -e -af $checkb "left" 90 myform;
formLayout -e -af $checkc "top" 35 myform;
formLayout -e -af $checkc "left" 170 myform;
formLayout -e -af $sep "top" 55 myform;
formLayout -e -af $sep "left" 11 myform;
formLayout -e -af $newform "top" 60 myform;
formLayout -e -af $newform "left" 11 myform;
formLayout -e -af $butn "top" 130 myform;
formLayout -e -af $butn "left" 75 myform;
showWindow $winName;
}

//procedure to query all the values from the window
//and run tests for error messages
global proc Values()
{
//variable creation here
string $grp1 = "XYZ_Trans";
string $grp2 = "YRot_Pan";
string $grp3 = "XRot_Tilt";
string $grp4 = "ZRot_Roll";
//query the values of the controls from main form
string $CamName = `textField -q -tx Newname`;
string $xyz = `checkBox -q -v xyztrans`;
string $yrotate = `checkBox -q -v yrot`;
string $xrotate = `checkBox -q -v xrot`;
string $zrotate = `checkBox -q -v zrot`;
string $node1 = `checkBox -q -v onenode`;
string $node2 = `checkBox -q -v twonode`;
string $node3 = `checkBox -q -v threenode`;
//check for error messages
if($CamName == "")
error "You forgot to give the Camera a name";
string $totalnode = $node1 + $node2 + $node3;
if($totalnode =="000")
error "You didn't select a Camera Type";
if($totalnode =="111")
error "You selected more than one Camera Type";
if($totalnode =="110")
error "You selected more than one Camera Type";
if($totalnode =="101")
error "You selected more than one Camera Type";
if($totalnode =="011")
error "You selected more than one Camera Type";
string $editnode = $xyz + $yrotate + $xrotate + $zrotate;
if($editnode =="0000")
error "You didn't select any Editable Nodes";
//camera creation statements
if ($node1 =="1")
camnode1($CamName);
if ($node2 =="1")
camnode2($CamName);
if ($node3 =="1")
camnode3($CamName);
//selecting the top node in hypergraph
select -r $CamName;
pickWalk -d up;
//setting attrib of the zrot node
if ($zrotate =="1")
zgroup($grp4);
//setting the attrib of the xrot node
if ($xrotate =="1")
xgroup($grp3);

//setting the attrib of the yrot node
if ($yrotate =="1")
ygroup($grp2);

//setting the attrib of the xyz trans
if ($xyz =="1")
xyzgroup($grp1);
}

//procedure for camera creation for 1 node camera
global proc camnode1(string $CamName)
{
camera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.01 -farClipPlane 1000 -orthographic 0 -orthographicWidth 30;
cameraMakeNode 1 "";
rename $CamName;
setAttr -lock true ($CamName +".tx");
setAttr -lock true ($CamName +".ty");
setAttr -lock true ($CamName +".tz");
setAttr -lock true ($CamName +".rx");
setAttr -lock true ($CamName +".ry");
setAttr -lock true ($CamName +".rz");
setAttr -lock true ($CamName +".sx");
setAttr -lock true ($CamName +".sy");
setAttr -lock true ($CamName +".sz");
}

//procedure for camera creation for 2 node camera
global proc camnode2(string $CamName)
{
camera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.01 -farClipPlane 1000 -orthographic 0 -orthographicWidth 30;
cameraMakeNode 2 "";
rename $CamName;
setAttr -lock true ($CamName +".tx");
setAttr -lock true ($CamName +".ty");
setAttr -lock true ($CamName +".tz");
setAttr -lock true ($CamName +".rx");
setAttr -lock true ($CamName +".ry");
setAttr -lock true ($CamName +".rz");
setAttr -lock true ($CamName +".sx");
setAttr -lock true ($CamName +".sy");
setAttr -lock true ($CamName +".sz");
}

//procedure for camera creation for 3 node camera
global proc camnode3(string $CamName)
{
camera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.01 -farClipPlane 1000 -orthographic 0 -orthographicWidth 30;
cameraMakeNode 3 "";
rename $CamName;
setAttr -lock true ($CamName +".tx");
setAttr -lock true ($CamName +".ty");
setAttr -lock true ($CamName +".tz");
setAttr -lock true ($CamName +".rx");
setAttr -lock true ($CamName +".ry");
setAttr -lock true ($CamName +".rz");
setAttr -lock true ($CamName +".sx");
setAttr -lock true ($CamName +".sy");
setAttr -lock true ($CamName +".sz");
}

//procedure for making zrotate node
global proc zgroup(string $grp4)
{
group -name $grp4; xform -os -piv 0 0 0;
setAttr -lock true ($grp4 +".tx");
setAttr -lock true ($grp4 +".ty");
setAttr -lock true ($grp4 +".tz");
setAttr -lock true ($grp4 +".rx");
setAttr -lock true ($grp4 +".ry");
setAttr -lock true ($grp4 +".sx");
setAttr -lock true ($grp4 +".sy");
setAttr -lock true ($grp4 +".sz");
}

//procedure for making xrotate node
global proc xgroup(string $grp3)
{
group -name $grp3; xform -os -piv 0 0 0;
setAttr -lock true ($grp3 +".tx");
setAttr -lock true ($grp3 +".ty");
setAttr -lock true ($grp3 +".tz");
setAttr -lock true ($grp3 +".ry");
setAttr -lock true ($grp3 +".rz");
setAttr -lock true ($grp3 +".sx");
setAttr -lock true ($grp3 +".sy");
setAttr -lock true ($grp3 +".sz");
}

//procedure for making yrot node
global proc ygroup(string $grp2)
{
group -name $grp2; xform -os -piv 0 0 0;
setAttr -lock true ($grp2 +".tx");
setAttr -lock true ($grp2 +".ty");
setAttr -lock true ($grp2 +".tz");
setAttr -lock true ($grp2 +".rx");
setAttr -lock true ($grp2 +".rz");
setAttr -lock true ($grp2 +".sx");
setAttr -lock true ($grp2 +".sy");
setAttr -lock true ($grp2 +".sz");
setAttr -lock true ($grp2 +".v");
}
//procedure for making xyztrans node
global proc xyzgroup(string $grp1)
{
group -name $grp1; xform -os -piv 0 0 0;
setAttr -lock true ($grp1 +".rx");
setAttr -lock true ($grp1 +".ry");
setAttr -lock true ($grp1 +".rz");
setAttr -lock true ($grp1 +".sx");
setAttr -lock true ($grp1 +".sy");
setAttr -lock true ($grp1 +".sz");
setAttr -lock true ($grp1 +".v");
}


Thanks,
Troy

Robert Bateman
10-25-2005, 01:38 PM
change the repeated

formLayout -e -af $cameraName "left" 85 myform;
formLayout -e -af $checka "top" 35 myform;

to something like...

formLayout -e -af $cameraName "left" 85
-af $checka "top" 35
// etc etc, until...
myform;


also, dont bother doing a conversion from checkBox q -v into a string, change that to an int. Later in your code, instead of doing the string comparisons, like

if($result=="1") {}

you can do

if($result) {

}

also, if you returned ints from the checkbox you could do....

int $totalnode = $node1 + $node2 + $node3;
if( $totalnode>1 ) {
// error: more than one camera
}

also, camnode1,camnode2 and camnode3 are exactly the same with the exception of 1 integer number. Could you not add another argument to a single camnode proc that specifies that integer?

Finally, aren't xgroup, ygroup and zgroup exactly the same? Do you really need three procs when 1 will do? the xyz group proc could also be the same if you had a myGroup proc taking a param for the visibility (should it be locked), a param for whether scale ges locked as well.

Robert Bateman
10-25-2005, 01:41 PM
oh yeah, if you only want 1 camera type selected could you not replace the checkBox's with an optionMenuGrp ?

Grayth
10-25-2005, 03:01 PM
Thanks for the crits,

I'll try and fix some of those.

I tried to figure out a way to sub in the change for the number in the CameraMakeNode command but haven't found anything that works yet...

the various groups are different in that I have locked out certain transforms for each which is the idea of the script to make camera animation easier. by just pickwalking up each group to keyframe..

but I appreciate it..as I said my first script..what can I say I'm a noob but nice to see how I can fix...I'll give it go

Troy

Robert Bateman
10-25-2005, 06:21 PM
global proc doLockAttrs(string $node,string $attrsToLock[])
{
for( $attr in $attrsToLock )
setAttr -lock true ($CamName +"." + $attr);
}

global proc camnode(string $CamName,int $val,string $attrsToLock[])
{
camera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.01 -farClipPlane 1000 -orthographic 0 -orthographicWidth 30;
cameraMakeNode $val "";
rename $CamName;
doLockAttrs($CamName,$attrsToLock);
}

string $attrsToLock[] = {"tx","ty","tz","sx","sy","sz","rx","ry","rz"};
// replace calls to camnode1 with...
camnode($camName,1,$attrsToLock);

// camnode2 ....
camnode($camName,2,$attrsToLock);

// camnode3....
camnode($camName,3,$attrsToLock);


//procedure for making yrot node (or xrot, or zrot)
global proc doMyGroup(string $grp)
{
group -name $grp; xform -os -piv 0 0 0;
string $attrsToLock[] = {"tx","ty","tz","sx","sy","sz","rx","ry","rz","v"};
doLockAttrs($grp,$attrsToLock);
}


global proc xyzroup(string $grp)
{
group -name $grp; xform -os -piv 0 0 0;
string $attrsToLock[] = {"sx","sy","sz","rx","ry","rz","v"};
doLockAttrs($grp,$attrsToLock);
}

Grayth
10-25-2005, 08:22 PM
Thanks, I really had to study out your answer but I got it to work. I learned tons off that.

I did have to change it a bit but the main idea is there the same as for each group node I add in the DAG has a different group transforms attributes to lock so I just added the same procedure you gave for each and a new lockattributes procedure..here's the adjusted code;



global proc Procam()
{
//variable creation here
string $grp1 = "XYZ_Trans";
string $grp2 = "YRot_Pan";
string $grp3 = "XRot_Tilt";
string $grp4 = "ZRot_Roll";
string $winName = "ProCam";
string $camnode = "1NodeCam";
string $camnode2 = "2NodeCam";
string $camnode3 = "3NodeCam";
//window check
if(`window -exists $winName`)
deleteUI -window $winName;
windowPref -remove $winName;
//window creation Layout here
string $myWindow= `window -title "Pro Camera Setup"
-w 260 -h 185 -s 0 -mnb 0 -mxb 0
$winName`;
//Main window Controls
string $form = `formLayout -nd 260 myform`;
string $labl= `text -label "Camera Name"`;
string $cameraName = `textField -w 150 Newname`;
string $sep =`separator -st "single" -w 225 divider`;
string $checka = `checkBox -l $camnode onenode`;
string $checkb = `checkBox -l $camnode2 twonode`;
string $checkc = `checkBox -l $camnode3 threenode`;
string $butn = `button -label "Create Camera" -c "Values" mybutton`;
//embedded form layout here
string $newform =`frameLayout -l "Select Editable Nodes" -w 225 -h 65 -p myform
-la "top" -bs "etchedIn"
-cll 0 -cl 0 embedform`;
//child of embededform Controls
string $form1 =`formLayout -nd 225 -p embedform nodeform`;
string $check1 = `checkBox -l $grp1 xyztrans`;
string $check2 = `checkBox -l $grp2 yrot`;
string $check3 = `checkBox -l $grp3 xrot`;
string $check4 = `checkBox -l $grp4 zrot`;
//Layout for embeded form Controls here
formLayout -e -af $check1 "top" 8
-af $check1 "left" 15
-af $check2 "top" 24
-af $check2 "left" 15
-af $check3 "top" 8
-af $check3 "left" 135
-af $check4 "top" 24
-af $check4 "left" 135 nodeform;

//layout for main window Controls here
formLayout -e -af $labl "top" 10
-af $labl "left" 10
-af $cameraName "top" 7
-af $cameraName "left" 85
-af $checka "top" 35
-af $checka "left" 10
-af $checkb "top" 35
-af $checkb "left" 90
-af $checkc "top" 35
-af $checkc "left" 170
-af $sep "top" 55
-af $sep "left" 11
-af $newform "top" 60
-af $newform "left" 11
-af $butn "top" 130
-af $butn "left" 75 myform;
showWindow $winName;
}

//procedure to query all the values from the window
//and run tests for error messages
global proc Values()
{
//variable Creation
string $grp1 = "XYZ_Trans";
string $grp2 = "YRot_Pan";
string $grp3 = "XRot_Tilt";
string $grp4 = "ZRot_Roll";
//query the values of the controls from main form
string $CamName = `textField -q -tx Newname`;
string $xyz = `checkBox -q -v xyztrans`;
string $yrotate = `checkBox -q -v yrot`;
string $xrotate = `checkBox -q -v xrot`;
string $zrotate = `checkBox -q -v zrot`;
int $node1 = `checkBox -q -v onenode`;
int $node2 = `checkBox -q -v twonode`;
int $node3 = `checkBox -q -v threenode`;
//check for error messages
if($CamName == "")
error "You forgot to give the Camera a name";
int $totalnode = $node1 + $node2 + $node3;
if($totalnode <1)
error "You didn't select a Camera Type";
if($totalnode >1)
error "You selected more than one Camera Type";
string $editnode = $xyz + $yrotate + $xrotate + $zrotate;
if($editnode =="0000")
error "You didn't select any Editable Nodes";
//camera creation statements
string $attrsToLock[] = {"tx","ty","tz","sx","sy","sz","rx","ry","rz"};
if ($node1 ==1)
camnode($CamName,1,$attrsToLock);
if ($node2 ==1)
camnode($CamName,2,$attrsToLock);
if ($node3 ==1)
camnode($CamName,3,$attrsToLock);
//selecting the top node in hypergraph
select -r $CamName;
pickWalk -d up;
//setting attrib of the zrot node
if ($zrotate =="1")
zrot($grp4);
//setting attrib of the xrot node
if ($xrotate =="1")
xrot($grp3);
//setting attrib of the yrot node
if ($yrotate =="1")
yrot($grp2);
//setting attrib of the xyz translate node
if ($xyz =="1")
xyztrans($grp1);
}

//creation procedure for the cameras
global proc camnode(string $CamName,int $val,string $attrsToLock[])
{
camera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.01 -farClipPlane 1000 -orthographic 0 -orthographicWidth 30;
cameraMakeNode $val "";
rename $CamName;
doLockAttrs($CamName,$attrsToLock);
}

//procedure to lock out the camera transforms
global proc doLockAttrs(string $CamName, string $attrsToLock[])
{
for( $attr in $attrsToLock )
setAttr -lock true ($CamName +"." + $attr);
}

//procedure for the zrotate node
global proc zrot(string $grp4)
{
group -name $grp4; xform -os -piv 0 0 0;
string $groupname = $grp4;
string $attrsToLock[] = {"tx","ty","tz","sx","sy","sz","rx","ry","v"};
dogroupLock($groupname,$attrsToLock);
}

//procedure for the xrotate node
global proc xrot(string $grp3)
{
group -name $grp3; xform -os -piv 0 0 0;
string $groupname = $grp3;
string $attrsToLock[] = {"tx","ty","tz","sx","sy","sz","ry","rz","v"};
dogroupLock($groupname,$attrsToLock);
}

//procedure for the yrotate node
global proc yrot(string $grp2)
{
group -name $grp2; xform -os -piv 0 0 0;
string $groupname = $grp2;
string $attrsToLock[] = {"tx","ty","tz","sx","sy","sz","rx","rz","v"};
dogroupLock($groupname,$attrsToLock);
}
//procedure for the xyz translate node
global proc xyztrans(string $grp1)
{
group -name $grp1; xform -os -piv 0 0 0;
string $groupname = $grp1;
string $attrsToLock[] = {"sx","sy","sz","rx","ry","rz","v"};
dogroupLock($groupname,$attrsToLock);
}
//procedure to lock attributes of group nodes
global proc dogroupLock(string $groupname, string $attrsToLock[])
{
for( $attr in $attrsToLock )
setAttr -lock true ($groupname +"." + $attr);
}


Troy

Robert Bateman
10-26-2005, 12:50 PM
There is no difference between the xrot yrot & zrot functions... You could substitute them with a single function :


global proc myrot(string $grp)
{
group -name $grp; xform -os -piv 0 0 0;
string $attrsToLock[] = {"tx","ty","tz","sx","sy","sz","ry","rz","v"};
// no need for the dogrouplock function, it does the same as the dolockattrs func!
doLockAttrs($grp,$attrsToLock);
}


your Values proc can be reduced to :


//and run tests for error messages
global proc Values()
{
// no real need for the $grp1, $grp2 variables etc, the are only ever used once
// within the function.

//query the values of the controls from main form
string $CamName = `textField -q -tx Newname`;

// change all of these to int... no reason to use strings for check boxes ever....
int $xyz = `checkBox -q -v xyztrans`;
int $yrotate = `checkBox -q -v yrot`;
int $xrotate = `checkBox -q -v xrot`;
int $zrotate = `checkBox -q -v zrot`;
int $node1 = `checkBox -q -v onenode`;
int $node2 = `checkBox -q -v twonode`;
int $node3 = `checkBox -q -v threenode`;

//check for error messages
if($CamName == "")
error "You forgot to give the Camera a name";
int $totalnode = $node1 + $node2 + $node3;

// [ref1] see below
if($totalnode <1)
error "You didn't select a Camera Type";
if($totalnode >1)
error "You selected more than one Camera Type";

// i guess no need to check for $xyz and $totalnode==0 since if totalnode==0,
// then the [ref1] section above would have already reported an error...

//camera creation statements
string $attrsToLock[] = {"tx","ty","tz","sx","sy","sz","rx","ry","rz"};
if ($node1)
camnode($CamName,1,$attrsToLock);
if ($node2)
camnode($CamName,2,$attrsToLock);
if ($node3)
camnode($CamName,3,$attrsToLock);

//selecting the top node in hypergraph
select -r $CamName;
pickWalk -d up;
//setting attrib of the zrot node
if ($zrotate)
myrot("ZRot_Roll");
//setting attrib of the xrot node
if ($xrotate)
myrot("XRot_Tilt");
//setting attrib of the yrot node
if ($yrotate)
myrot("YRot_Pan");
//setting attrib of the xyz translate node
if ($xyz)
xyztrans("XYZ_Trans");
}


FYI, there is no point checking for $node==1 within an if statement. Basically with an if statement, if you did :


if(0) {
// never executed
}

if(1) {
// always executed.
}


Therefore if you change the 0 or 1 to a variable, you get...


$var = 0;

if($var) {
// never executed
}

$var = 1;

if($var) {
// always executed since $var is not 0
}

CGTalk Moderation
10-26-2005, 12:50 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.