Maya for 3D Printing - Rapid Prototyping
In this course we're going to look at something a little different, creating technically accurate 3D printed parts.
# 1 25-10-2005 , 07:41 PM
Grayth's Avatar
Subscriber
Join Date: Oct 2003
Location: Brantford Ontario Canada
Posts: 43

Camera setup script finished..enjoy

here's a script I've been working on. It'll make camera animation alot easier. Some people have helped me create it when I got stuck on the coding, so if you like it use it.

What it will do is create a number of cameras with a name ou provide and create group transforms so you can animate easily for each transform node, as I lock out the non editable/animatable transforms you don't want..

here's the code...

//This script is inspired from Eric Hanson's Digital Sets DVd's
//Many thanks to alot of folks on cgtalk
//especially Andrew, aka Westimad and Robert Bateman
//Please distribute this script freely
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);
}


Think Twice Split Poly Once
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads