home *** CD-ROM | disk | FTP | other *** search
/ Learning Maya 3 / Learning_Maya_3.iso / docs / mel_scripts / includes / IKdisableWin.mel < prev    next >
Encoding:
Text File  |  2000-05-17  |  4.7 KB  |  163 lines

  1. //
  2. // Copyright (C) 1997-2000 Alias|Wavefront,
  3. // a division of Silicon Graphics Limited.
  4. //
  5. // The information in this file is provided for the exclusive use of the
  6. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  7. // and incorporate this code into other products for purposes authorized
  8. // by the Alias|Wavefront license agreement, without fee.
  9. //
  10. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  11. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  12. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  13. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  14. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. // PERFORMANCE OF THIS SOFTWARE.
  17. //
  18. //
  19. //  Alias|Wavefront Script File
  20. //  MODIFY THIS AT YOUR OWN RISK
  21. //
  22. // Creation Date:  18 March 1998
  23. // Author:         Shawn Dunn
  24. //
  25. //
  26. //  Procedure Name:
  27. //
  28. //      IKdisableWin
  29. //
  30. //  Description:
  31. //
  32. //      This script creates a window for enabling or disabling IK handles
  33. //      When an IK handle has been selected you push the button in the
  34. //      window and it selects all the joints associated with it and
  35. //    then disables or enables the IK handle and sets keyframes on
  36. //    the selected joints. This makes it easy to switch between animating
  37. //    with forward and inverse kinematics.
  38. //
  39.  
  40. //This procedure selects the joints associated with an IK handle. Sets
  41. //keyframes on the IK handle and the joints. It then disables or enables
  42. //the IK handle.
  43. //
  44.  
  45. global proc ikOnOff()
  46. {
  47.  
  48.     //get a listing of any active IK handles
  49.     //
  50.     string $activeIKHandle[] = `ls -sl -type "ikHandle"`;
  51.  
  52.     //check to see if an IK handle is selected if it is not prompt
  53.     //the user to select one
  54.     //
  55.     if (size($activeIKHandle) == 0)
  56.         {
  57.         print "Please pick an IK Handle";
  58.         }
  59.  
  60. //if the user has picked an IK handle do the following
  61. //
  62.     else
  63.     {
  64.  
  65. //A for loop is needed in case more than one IK handle is selected
  66. //
  67.         for ($activeIK in $activeIKHandle)
  68.  
  69.         {
  70.         //We need to make sure that only one IK handle is selected
  71.         //
  72.         select $activeIK;
  73.  
  74.         //We need to be able to pick the joints that are contained within the
  75.         //IK handle.The listConnections command is used to see what joints are
  76.         //connected to the IK handle.
  77.         //
  78.         
  79.         string $endEffector[] = `listConnections -type "ikEffector"`;
  80.         string $lastJoint[] = `listConnections -type "joint" $endEffector`;
  81.         string $firstJoint[] = `listConnections -type "joint"`;
  82.  
  83.         //Add the first and last joints to the selection and 
  84.         //then put the result in a variable
  85.         //
  86.         select -add $lastJoint $firstJoint;
  87.         string $selectAll[] = `ls -sl`;
  88.         select $lastJoint;
  89.         $lastJoint = `ls -sl`;
  90.  
  91.         //Pick the last joint and then use pickWalk to go up to the first joint
  92.         //using a while loop. Keep adding the new joint to the selection
  93.         //
  94.                 while ($firstJoint[0] != $lastJoint[0])
  95.                 {
  96.                         string $newSelection[] = `pickWalk -d "up"`;
  97.                         select $selectAll $newSelection;
  98.                         $selectAll = `ls -sl`;
  99.                         select $newSelection;
  100.                         $lastJoint = $newSelection;
  101.                 }
  102.         // Select the IK handle and the joints and set keyframes on them
  103.         //
  104.         select $selectAll;
  105.         setKeyframe;
  106.  
  107.         //Enable or disable the IK handle. First check to see if the IK
  108.         //handle is on or off
  109.         //
  110.         if (`getAttr ($activeIK + ".solverEnable")` == 1)
  111.             {
  112.             //if the IK handle is on turn it off by changing 
  113.             //the attribute
  114.             //
  115.             setAttr ($activeIK + ".solverEnable") 0;
  116.             print ($activeIK + "'s solver has been disabled\n");
  117.                 }
  118.         else
  119.                 {
  120.             //if the IK handle is off turn it on by changing 
  121.             //the attribute
  122.             //
  123.             setAttr ($activeIK + ".solverEnable") 1;
  124.             print ($activeIK + "'s solver has been enabled\n");
  125.             }
  126.         }
  127.  
  128. //After running all the above return the selection to the original 
  129. //IK handles
  130. //
  131. select $activeIKHandle;
  132.     }
  133. }
  134.  
  135.  
  136.  
  137. //Create a window with a button
  138. //
  139. global proc IKdisableWin()
  140. {
  141.         string $wind = "IKdisable";
  142.  
  143.         //Check and see if the window exists
  144.         //
  145.         if (!`window -exists $wind`)
  146.         {
  147.  
  148.         window
  149.                 -width 150
  150.                 -title "Disable/Enable IK"
  151.                 $wind;
  152.  
  153.         columnLayout
  154.                 -adjustableColumn true;
  155.  
  156.         button
  157.                 -label "Disable/Enable"
  158.                 -command "ikOnOff";
  159.  
  160.         showWindow $wind;
  161.         }
  162. }
  163.