// Script: js_greasePencil_3.mel // Author: Jason Schleifer // jason.schleifer@gmail.com // // Date: Aug 12, 2004 // Updated: April 30, 2005 // // Descr: This is a quick hack to simulate a greasePencil interface for maya. // // May 22, 2005 - Fixes // -------------------- // o fixed size of planes for orthographic views // // April 30, 2005 - Additions // -------------------------- // o added post frame ghosting // o added warning for pre-frame 1 errors // o made it so when you store a frame, it automatically removes it from the timed frames // o removed Trans and Scale fields, added ability to select frames instead // o added ability to shift frames up and down // o can now select "stored" frames // o can now toggle template and visibility of "stored" frames // // April 27, 2005 - Additions // -------------------------- // o Added ability to change timing of drawings // o New cleaner interface which shows what frames drawings are on // o Snap to drawing by clicking on item in interface // o Remembers previous camera // o Visibility toggle // o Curves are no longer stored under the camera // o Can scale and translate plane // o can turn on and off the ghosting // o added ability to store frames so they stay throughout the shot // // // To Do: // ------ // o Make it so the tool isn't name based // o Add ability to create multiple grease pencils per camera // o Add ability to color lines // o Add ability to modify thickness global proc js_greasePencil_3 () { $win = "js_greasePencilWin"; if (`window -exists $win`) deleteUI $win; createGreasePencilWin $win; showWindow $win; } global proc js_gpShiftFrames (string $direction) { // This procedure will shift all frames from the current one on either up or down // the first frame will not go above frame 1. // inputs are "up" and "down" // first get the camera and curGP string $om = "gp_om"; $cam = `optionMenuGrp -q -v $om`; if (`attributeQuery -exists -node $cam "gpGrp"`) { // get a list of all the items in the textScrollList // then get the selected item number string $items[] = `textScrollList -q -ai js_gpTSL`; int $sel[] = `textScrollList -q -sii js_gpTSL`; if (size($sel) > 0) { $size = size($items); if (($sel[0] == 1) && ($direction == "up") && ($items[0] == 1)) { confirmDialog -m ("Sorry, can't go up past frame 1!"); } else { int $exit=0; //print ("Sel[0] = "+$sel[0] + "\n"); if (($sel[0]-2) >= 0) { int $curItem = $items[($sel[0]-1)]; int $prevItem = $items[($sel[0]-2)]; if (($direction == "up") && (($curItem-1) == $prevItem)) { confirmDialog -m ("You can't go past this value!"); $exit = 1; } } if ($exit == 0) { if ($direction == "down") { for ($x = ($size-1); $x >=($sel[0]-1); $x--) { $name = ("gp_"+$cam+"_"+$items[$x]); $dir = 1; int $newValue = (int($items[$x]) + 1); $newName = ("gp_"+$cam+"_"+$newValue); rename $name $newName; } } else { for ($x = ($sel[0]-1); $x < $size; $x++) { $name = ("gp_"+$cam+"_"+$items[$x]); int $newValue = (int($items[$x]) -1); $newName = ("gp_"+$cam+"_"+$newValue); rename $name $newName; } } js_updateGPVis $cam; js_pmUpdateInterface; // now select the item textScrollList -e -sii $sel[0] js_gpTSL; } } } } } global proc string js_getCurGP ( string $camera) { $curFrame = `currentTime -q`; // first check and see if the frame exists $greasePlane = ("gp_"+$camera + "_" + $curFrame); return $greasePlane; } global proc js_addGreasePencilFrame ( string $camera ) { // this procedure will add a grease pencil plane for the current frame for the given camera // first check to see if we're on a frame less than frame 1. If so, return a warning. if (`currentTime -q` < 1) { confirmDialog -m ("The Grease Pencil script does not work on any frames less than 1."); } else { $greasePlane = `js_getCurGP $camera`; string $camGrp; if (`objExists $greasePlane`) { // it already exists, do nothing } else { // create the plane $plane = `nurbsPlane -p 0 0 0 -ax 0 1 0 -w 1 -lr 1 -d 3 -u 1 -v 1 -ch 0`; $greasePlane = `rename $plane $greasePlane`; // ** create a group which will be point and orient constrained to the // camera. This group will be the thing that all planes are under // first check and see if it already exists if (!`attributeQuery -exists -node $camera "gpGrp"`) { $dup = `duplicate $camera`; delete `listRelatives -f -s $dup[0]`; $camGrp = `rename $dup[0] ($camera+ "_gpGrp")`; // now add an attribute to the camera which lets us find the group addAttr -ln "gpGrp" -at "message" $camera; // connect the attribute connectAttr ($camGrp + ".message") ($camera+ ".gpGrp"); // add attributes for ghosting, pre and post addAttr -ln "preGhost" -at "bool" $camGrp; addAttr -ln "postGhost" -at "bool" $camGrp; setAttr ($camGrp + ".preGhost") 1; setAttr ($camGrp + ".postGhost") 1; } else { $camGrp = `jsGetCamGrp $camera`; } // now point and orientConstrain the camGrp to the camera select $camera $camGrp; pointConstraint; orientConstraint; // parent the greasePlane to the camGrp parent $greasePlane $camGrp; // set the attributes setAttr ($greasePlane + ".tx") 0; setAttr ($greasePlane + ".ty") 0; setAttr ($greasePlane + ".tz") -1; setAttr ($greasePlane + ".rx") 90; setAttr ($greasePlane + ".ry") 0; setAttr ($greasePlane + ".rz") 0; if (`getAttr ($camera + ".orthographic")`) { setAttr ($greasePlane + ".sx") 32; setAttr ($greasePlane + ".sy") 1; setAttr ($greasePlane + ".sz") 20; } else { setAttr ($greasePlane + ".sx") 3; setAttr ($greasePlane + ".sy") 1; setAttr ($greasePlane + ".sz") 2; } // get the shape $shape = `listRelatives -f -s $greasePlane`; setAttr ($shape[0] + ".overrideEnabled") 1; setAttr ($shape[0] + ".overrideShading") 0; setAttr ($shape[0] + ".overrideDisplayType") 2; // make sure the camera is visible setAttr ($camGrp + ".v") 1; } js_updateGPVis $camera; js_setGPLive $camera; } } global proc int js_createGPFScriptJob (string $camera) { // this proc will create the scriptJob that makes it so every time the frame changes and stops, the // approriate visible gpf will be active print "Grease Pencil Tool: ON"; $job = `scriptJob -cf "playingBack" ("js_setGPLive " + $camera )`; scriptJob -event "ToolChanged" ("js_removeGPFScriptJob " + $job ) -ro 1; return $job; } global proc js_setGPLive (string $camera) { // this will find the currently active gp for the camera & make it live string $camGrp; $camGrp = `jsGetCamGrp $camera`; string $gp; //$gp = `js_findVisGPS $camera`; $gp = `js_findVisGPS $camGrp`; if ($gp == "") { //warning "No grease pencil planes available for this camera. Creating one.."; js_addGreasePencilFrame $camera; $gp = `js_findVisGPS $camGrp`; } select $gp; MakeLive; select -d; } global proc string js_findVisGPS (string $camera) { string $gp; string $children[0]; $children = `listRelatives -c -type "transform" $camera`; string $child; for ($child in $children) { string $break[0]; tokenize ($child, "_", $break); if ($break[0] == "gp") { // check and see if it's visible. if ((`getAttr ($child + ".v")`) && (!`getAttr ($child + ".template")`)) { $gp = $child; } } } return $gp; } global proc js_removeGPFScriptJob (int $job) { string $objs[0]; $objs = `ls -sl`; print "Grease Pencil Tool: OFF"; scriptJob -kill $job; select -d; MakeLive; select $objs; } global proc js_setGPTool (string $camera) { // This procedure sets the tool to the pencil // first, we need to set the tool: curveSketchToolScript 4; refresh; // now start the scriptJobs js_createGPFScriptJob $camera; js_setGPLive $camera; } global proc js_gpSelectFrame () { string $items[] = `textScrollList -q -si js_gpTSL`; if (size($items) > 0) { string $om = "gp_om"; $cam = `optionMenuGrp -q -v $om`; setToolTo "selectSuperContext"; $name = ("gp_"+$cam+"_"+$items[0]); if (`objExists $name`) select $name; else warning ("Cannot select " +$name+ " because it doesn't exist..\n"); } } global proc js_gpSelectStoredFrame () { string $items[] = `textScrollList -q -si js_gpStoredFramesTSL`; if (size($items) > 0) { string $om = "gp_om"; $cam = `optionMenuGrp -q -v $om`; setToolTo "selectSuperContext"; $name = ("stored_gp_"+$cam+"_"+$items[0]); if (`objExists $name`) select $name; else warning ("Cannot select " +$name+ " because it doesn't exist..\n"); } } global proc js_removeGPFrame (string $camera) { // this proc will remove a gp from the selected frame in the // greasePencilwindow string $items[] = `textScrollList -q -si js_gpTSL`; if (size($items) > 0) { // attempt to delete it $greasePlane = ("gp_"+$camera+"_"+$items[0]); if (`objExists $greasePlane`) { // it exists, delete it delete $greasePlane; js_updateGPVis $camera; js_setGPLive $camera; //$gp = `js_findVisGPS $camera`; //print ("Current Vis: " + $gp + "\n"); } } js_pmUpdateInterface; } global proc js_removeGPStoredFrame (string $camera) { // this proc will remove a stored frame from the selected frame in the // greasePencilwindow string $items[] = `textScrollList -q -si js_gpStoredFramesTSL`; if (size($items) > 0) { // attempt to delete it $greasePlane = ("stored_gp_"+$camera+"_"+$items[0]); if (`objExists $greasePlane`) { // it exists, delete it delete $greasePlane; js_updateGPVis $camera; js_setGPLive $camera; //$gp = `js_findVisGPS $camera`; //print ("Current Vis: " + $gp + "\n"); } } js_pmUpdateInterface; } global proc js_makeFrameActive (string $camera) { js_addGreasePencilFrame $camera; } global proc js_removeGPFrame (string $camera) { // this proc will remove a gp from the selected frame in the // greasePencilwindow string $items[] = `textScrollList -q -si js_gpTSL`; if (size($items) > 0) { // attempt to delete it $greasePlane = ("gp_"+$camera+"_"+$items[0]); if (`objExists $greasePlane`) { // it exists, delete it delete $greasePlane; js_updateGPVis $camera; js_setGPLive $camera; //$gp = `js_findVisGPS $camera`; //print ("Current Vis: " + $gp + "\n"); } } js_pmUpdateInterface; } global proc js_makeFrameActive (string $camera) { js_addGreasePencilFrame $camera; $greasePlane = `js_getCurGP $camera`; select $greasePlane; MakeLive; } global proc js_makeFrameNotActive (string $camera) { select -d; MakeLive; } global proc int js_gpGetValidReturn ( string $camera, int $initial) { int $return = $initial; string $result = "good"; string $text; int $enteredValue; string $value; string $newValue; // this proc will query the user for a new number to enter. It will return // the number as long as it doesn't match another pre-existing frame, other // than the one that they started with do { $return = $initial; $result = "good"; $text = ""; $enteredValue = 0; $value = ""; $newValue = ""; $value = `promptDialog -title "Set New Frame" -message "New Frame #" -button "OK" -button "Cancel" -defaultButton "OK" -cancelButton "Cancel" -text $initial -dismissString "Cancel" `; if ($value == "OK") { $newValue = `promptDialog -q -text `; $enteredValue = $newValue; if ($enteredValue == $initial) { $result = "good"; $return = $initial; } else { // now we have to check all the other items in the list to make // sure it doesn't match one of those. string $items[] = `textScrollList -q -ai js_gpTSL`; for ($item in $items) { // now check the newValue and see if it matches an // item.. if ($enteredValue == $item) { $result = "bad"; confirmDialog -m "Ooops! You already have a drawing on this frame!"; } } if ($result == "good") $return = $enteredValue; } } else { $result = "good"; $return = $initial; } } while ($result == "bad"); // ("Returning: " + $return + "\n"); return $return; } global proc createGreasePencilWin (string $win) { window -title "Poor-Man's Grease Pencil" $win; $f = `formLayout -nd 100`; $c = `columnLayout -adj true`; text -align "left" -label "Poor Man's Grease Pencil\n\n"; text -align "left" -label "Please choose a camera to work with."; setParent $f; $om = `optionMenuGrp -cw 1 75 -adj 2 -ad2 1 -cal 1 "right" -l "Camera:" gp_om`; // check for the optionVar string $prevCam; if (`optionVar -exists "js_gpCameraOptionVar"`) { $prevCam = `optionVar -q "js_gpCameraOptionVar"`; } $cameras = `ls -type camera`; for ($cam in $cameras) { $p = `listRelatives -p $cam`; menuItem -l $p[0]; if ($prevCam != "") { if ($p[0] == $prevCam) { optionMenuGrp -e -v $prevCam $om; } } } setParent $f; // create a textScrollList, this will show all the frames for the current // camera $tsl = `textScrollList -nr 10 -dcc "js_gpDoubleClickTSL" -sc "js_goSelectedFrame" js_gpTSL`; // add a checkbox for visibility $cbg = `checkBoxGrp -cw 1 50 -cal 1 "right" -l "Vis:" -ncb 1 js_pmCheckBoxGrp`; $gbg = `checkBoxGrp -cw 1 50 -cw 2 50 -cw 3 50 -l "Ghost:" -l1 "Pre" -l2 "Post" -ncb 2 -on1 "js_gpGhost 1 1" -of1 "js_gpGhost 1 0" -on2 "js_gpGhost 2 1" -of2 "js_gpGhost 2 0" -cal 1 "right" js_pmGhostCheckBoxGrp`; $b1 = `button -l "Use Draw Tool" -c "js_pmDrawToolGo"`; $b2 = `button -l "+" -c "js_pmAddFrame"`; $b3 = `button -l "-" -c "js_pmDelFrame"`; $b4 = `button -l "Store" -c "js_gpSaveFrame"`; $b7 = `button -l "Down" -c "js_gpShiftFrames down"`; $b8 = `button -l "Up" -c "js_gpShiftFrames up"`; $b9 = `button -l "Select" -c "js_gpSelectFrame"`; $fl = `frameLayout -label "Extras" -borderStyle "in" -cl true -cll true js_gpFrameLayout`; columnLayout -adj true; //attrFieldGrp -nf 3 -l "GP Translate: " -cw 1 150 -cw 2 50 -cw 3 50 -cw 4 50 -enable 0 js_gpTransAFG; //attrFieldGrp -nf 3 -l "GP Scale: " -cw 1 150 -cw 2 50 -cw 3 50 -cw 4 50 -enable 0 js_gpScaleAFG; formLayout -nd 100 js_gpStoredFL; $st = `text -align "left" -l "Stored Frames"`; $stl = `textScrollList -sc "js_gpStoredTSLSel" -ams 1 -nr 5 js_gpStoredFramesTSL`; $stlb1 = `button -l "-" -c "js_gpDeleteStoredFrame" js_gpStoredFramesB`; $stlb2 = `button -l "Select" -c "js_gpSelectStoredFrame"`; $stcbg = `checkBoxGrp -cw 1 75 -cal 1 "right" -l "Vis:" -ncb 1 js_pmStoredCheckBoxGrp`; $stgbg = `checkBoxGrp -cw 1 75 -cal 1 "right" -l "Template:" -ncb 1 js_pmStoredTemplateCheckBoxGrp`; formLayout -e -af $st left 5 -af $st right 5 -af $st top 5 -af $stgbg left 5 -ap $stgbg right 5 50 -af $stgbg bottom 5 -ap $stcbg left 5 50 -af $stcbg right 5 -af $stcbg bottom 5 -af $stl left 5 -ac $stl top 1 $st -ap $stl right 0 80 -ac $stl bottom 5 $stcbg -ac $stlb1 left 5 $stl -af $stlb1 right 5 -ac $stlb1 top 1 $st -ac $stlb2 left 5 $stl -af $stlb2 right 5 -ac $stlb2 top 1 $stlb1 js_gpStoredFL; formLayout -e -af $c top 5 -af $c left 5 -af $c right 5 -af $om left 0 -ap $om right 5 50 -ac $om top 5 $c -ap $cbg left 5 50 -ac $cbg top 5 $c -ap $cbg right 5 75 -ap $gbg left 5 50 -ac $gbg top 5 $cbg -af $gbg right 0 -af $b1 left 5 -af $b1 right 5 -af $b1 bottom 5 -af $fl left 5 -af $fl right 5 -ac $fl bottom 5 $b1 -af $tsl left 5 -ac $tsl top 5 $gbg -ap $tsl right 0 80 -ac $tsl bottom 5 $fl -ac $b2 left 2 $tsl -ac $b2 top 5 $gbg -af $b2 right 5 -ac $b3 left 2 $tsl -ac $b3 top 5 $b2 -af $b3 right 5 -ac $b4 left 2 $tsl -ac $b4 top 5 $b7 -af $b4 right 5 -ac $b7 left 2 $tsl -ac $b7 top 5 $b8 -af $b7 right 5 -ac $b8 left 2 $tsl -ac $b8 top 5 $b3 -af $b8 right 5 -ac $b9 left 2 $tsl -ac $b9 top 5 $b4 -af $b9 right 5 $f; optionMenuGrp -e -cc ("js_pmUpdateInterface" ) $om; js_pmUpdateInterface; } global proc js_goSelectedFrame () { // get the current frame string $items[] = `textScrollList -q -si js_gpTSL`; if (size($items) > 0) currentTime -e $items[0]; } global proc js_pmUpdateInterface () { string $om = "gp_om"; string $cbg = "js_pmCheckBoxGrp"; checkBoxGrp -e -v1 0 -v2 0 js_pmGhostCheckBoxGrp; checkBoxGrp -e -v1 0 -enable 0 js_pmStoredCheckBoxGrp; checkBoxGrp -e -v1 0 -enable 0 js_pmStoredTemplateCheckBoxGrp; // updates the interface based on the optionMenuGrp // first get the current camera showing $cam = `optionMenuGrp -q -v $om`; //attrFieldGrp -e -enable 0 js_gpScaleAFG; //attrFieldGrp -e -enable 0 js_gpTransAFG; // save the camera as an optionVar optionVar -sv "js_gpCameraOptionVar" $cam; textScrollList -e -ra js_gpTSL; textScrollList -e -ra js_gpStoredFramesTSL; // now check and see if a plane exists for that optionMenuGrp if (`attributeQuery -exists -node $cam "gpGrp"`) { checkBoxGrp -e -enable 1 $cbg; $camGrp = `jsGetCamGrp $cam`; connectControl -index 2 $cbg ($camGrp + ".v"); $preGhost = `getAttr ($camGrp + ".preGhost")`; $postGhost = `getAttr ($camGrp + ".postGhost")`; checkBoxGrp -e -v1 $preGhost -v2 $postGhost js_pmGhostCheckBoxGrp; // set the attrFieldGrp for the scale //attrFieldGrp -e -enable 1 -at ($camGrp + ".scale") js_gpScaleAFG; //attrFieldGrp -e -enable 1 -at ($camGrp + ".translate") js_gpTransAFG; // now fill the textScrollList with frame numbers string $children[0]; $children = `js_getGPList $cam`; int $ordered[0]; int $num = 0; for ($item in $children) { string $break[0]; tokenize ($item, "_", $break); $ordered[$num++] = $break[2]; } $ordered = `sort $ordered`; for ($number in $ordered) { textScrollList -e -a $number js_gpTSL; } // now fill the stored textScrollList with frame numbers string $children2[0]; $children2 = `js_getStoredGPList $cam`; string $ordered2[0]; int $num2 = 0; for ($item in $children2) { string $break[0]; tokenize ($item, "_", $break); textScrollList -e -a $break[3] js_gpStoredFramesTSL; } } else { checkBoxGrp -e -enable 0 $cbg; } } global proc js_gpStoredTSLSel () { // this proc will check the selected TSL and see if it should turn on or off the // checkboxes for the hilighted stored plane string $sel[0]; $sel = `textScrollList -q -si js_gpStoredFramesTSL`; if (size($sel) > 0) { checkBoxGrp -e -enable 1 js_pmStoredCheckBoxGrp; checkBoxGrp -e -enable 1 js_pmStoredTemplateCheckBoxGrp; string $om = "gp_om"; $cam = `optionMenuGrp -q -v $om`; $name = ("stored_gp_"+$cam+"_"+$sel[0]); if (`objExists $name`) { connectControl -index 2 js_pmStoredCheckBoxGrp ($name + ".v"); connectControl -index 2 js_pmStoredTemplateCheckBoxGrp ($name + ".template"); } } else { checkBoxGrp -e -v1 0 -enable 0 js_pmStoredCheckBoxGrp; checkBoxGrp -e -v1 0 -enable 0 js_pmStoredTemplateCheckBoxGrp; } } global proc js_gpGhost (int $cb, int $value) { // set the value of the checkbox either on or off // first get the camera $cam = `optionMenuGrp -q -v gp_om`; string $cbg = "js_pmGhostCheckBoxGrp"; // now get the camGrp $camGrp = `jsGetCamGrp $cam`; // set the value of ghost if ($cb == 1) { setAttr ($camGrp + ".preGhost") $value; checkBoxGrp -e -v1 $value $cbg; } else { setAttr ($camGrp + ".postGhost") $value; checkBoxGrp -e -v2 $value $cbg; } js_updateGPVis $cam; } global proc js_gpDoubleClickTSL () { // if the textScrollList is double-clicked, that means the user may want to // change the frame number that the image is currently on. // // first, get the camera string $om = "gp_om"; string $tsl = "js_gpTSL"; string $cam; string $item; string $items[]; $cam = `optionMenuGrp -q -v $om`; // now find out what was selected $items = `textScrollList -q -si $tsl`; $item = $items[0]; // pop up a box which will ask the user to enter a new frame number $result = `js_gpGetValidReturn $cam $item`; // now we have a result.. check and see if the result is the same as the // $item. If so, do nothing.. if not, re-order things! woo! if ($result != $item) { // create a new name for the item $newName = ("gp_"+$cam+"_"+$result); // the old name is $oldName = ("gp_"+$cam+"_"+$item); // rename it rename $oldName $newName; // now update everything js_updateGPVis $cam; js_setGPLive $cam; js_pmUpdateInterface; // now go to that frame textScrollList -e -si $result js_gpTSL; currentTime -e $result; } } global proc js_pmAddFrame() { // get the current value in the camera pullDown $cam = `optionMenuGrp -q -v gp_om`; js_addGreasePencilFrame $cam; js_pmUpdateInterface; } global proc js_pmDelFrame() { // get the current value in the camera pullDown $cam = `optionMenuGrp -q -v gp_om`; js_removeGPFrame $cam; } global proc js_gpDeleteStoredFrame() { // get the current value in the camera pullDown $cam = `optionMenuGrp -q -v gp_om`; js_removeGPStoredFrame $cam; } global proc js_pmDrawToolGo () { // get the current value in the camera pullDown $cam = `optionMenuGrp -q -v gp_om`; js_setGPTool $cam; } global proc string jsCreateExtrudeCircle (string $grp) { // create a circle and connect it to the camGrp string $circle[0]; $circle = `circle -radius .005`; hide $circle; addAttr -ln "gp_ExtrudeCircle" -at "message" $grp; connectAttr ($circle[0] + ".message") ($grp + ".gp_ExtrudeCircle"); return ($circle[0]); } global proc string jsGetExtrudeCircle (string $camGrp) { $tmp = `listConnections ($camGrp + ".gp_ExtrudeCircle")`; return ($tmp[0]); } global proc string jsGetCamGrp (string $camera) { string $camGrp; string $tmp[0]; $tmp = `listConnections ($camera + ".gpGrp")`; $camGrp = $tmp[0]; return $camGrp; } global proc string[] js_getStoredGPList ( string $camera ) { // get a list of all the gps for the current camera string $list[0]; int $count = 0; string $camGrp; $camGrp = `jsGetCamGrp $camera`; string $children[0]; $children = `listRelatives -c -type "transform" $camGrp`; string $child; for ($child in $children) { string $break[0]; tokenize ($child, "_", $break); if ($break[0] == "stored") { $list[$count++] = $child; } } return $list; } global proc string[] js_getGPList ( string $camera ) { // get a list of all the gps for the current camera string $list[0]; int $count = 0; string $camGrp; $camGrp = `jsGetCamGrp $camera`; string $children[0]; $children = `listRelatives -c -type "transform" $camGrp`; string $child; for ($child in $children) { string $break[0]; tokenize ($child, "_", $break); if ($break[0] == "gp") { $list[$count++] = $child; } } return $list; } global proc js_gpSaveFrame () { // this procedure will duplicate the hilighted frame and "store" it for // later use. // first find out which one is selected string $om = "gp_om"; string $tsl = "js_gpTSL"; string $cam; string $item; $cam = `optionMenuGrp -q -v $om`; // now find out what was selected $items = `textScrollList -q -si $tsl`; if (size($items) > 0) { // prompt the user for a name $result = `promptDialog -t "New Stored Frame" -m "What would you like to call this frame?" -b "Store it" -b "Cancel" -db "Store it" -cb "Cancel" `; if ($result == "Store it") { $value = `promptDialog -q -text`; // the name of the hilighted frame $name = ("gp_"+$cam+"_"+$items[0]); // duplicate it string $dup[0]; $dup = `duplicate $name`; $newName = `rename $dup[0] ("stored_gp_"+$cam+"_"+$value)`; // now remove the drawing so it's not part of the animated bit js_pmDelFrame; js_pmUpdateInterface; } } } global proc js_updateGPVis (string $camera) { // first get a list of all the grease pencils in the list string $camGrp; string $children[0]; string $gps[0]; int $frames[0]; int $count = 0; int $count2 = 0; int $count3 = 0; $camGrp = `jsGetCamGrp $camera`; //$children = `listRelatives -c -type "transform" $camera`; $children = `listRelatives -c -type "transform" $camGrp`; string $child; for ($child in $children) { string $break[0]; tokenize ($child, "_", $break); if ($break[0] == "gp") { $frames[$count++] = $break[size($break)-1]; } } $frames = `sort $frames`; int $preGhost = `getAttr ($camGrp + ".preGhost")`; int $postGhost = `getAttr ($camGrp + ".postGhost")`; for ($x = 0; $x < size($frames); $x++) { // first delete all the keys on the visibility for the gp $gp = ("gp_" + $camera + "_" + $frames[$x]); //print ("Working on " + $gp + "\n"); if (`objExists $gp`) catch (`cutKey -at "visibility" -at "template" $gp`); // now, set a key for the value of 0 at $x before this current value, unless $x = 0; if ($x > 0) { //if ($gGhost) // setKeyframe -at "visibility" -v 0 -ott "step" -t ($frames[$x-1]) -t ($frames[$x+2]) $gp; //else $cmd = ("setKeyframe -at \"visibility\" -v 0 -ott \"step\" -t ("+$frames[$x-1]+") -t ("+$frames[$x+1 + $preGhost]+") \""+$gp+"\""); eval $cmd; } else if ($x == 0) { //if ($gGhost) //setKeyframe -at "visibility" -v 0 -ott "step" -t ($frames[$x+2]) $gp; //else //print ("Booger\n"); $cmd = ("setKeyframe -at \"visibility\" -v 0 -ott \"step\" -t ("+$frames[$x+1 + $preGhost]+") \""+$gp+"\""); eval $cmd; } // now set a key for it to be on at this frame if (`objExists $gp`) { if ($x > 0) { setKeyframe -at "visibility" -v 1 -ott "step" -t ($frames[$x-$postGhost]) $gp; setKeyframe -at "template" -v 1 -ott "step" -t ($frames[$x - $postGhost]) $gp; setKeyframe -at "template" -v 0 -ott "step" -t ($frames[$x]) $gp; } else { setKeyframe -at "visibility" -v 1 -ott "step" -t ($frames[$x]) $gp; setKeyframe -at "template" -v 0 -ott "step" -t ($frames[$x]) $gp; } setKeyframe -at "template" -v 1 -ott "step" -t ($frames[$x+1]) $gp; } } }