Advertisement
ylSiew

Untitled

Jan 19th, 2015
1,129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.26 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # menu setup script for rig tools
  5.  
  6. __author__ = 'Siew Yi Liang'
  7.  
  8. import logging
  9.  
  10. import maya.cmds as mc
  11. import maya.mel as mel
  12.  
  13. # setup streamhandler
  14. logging.basicConfig()
  15.  
  16. # create logger (creates StreamHandler with default Formatter and
  17. # adds it to the logger object
  18. log = logging.getLogger(__name__)
  19. log.setLevel(logging.INFO)
  20.  
  21. # get the current maya version
  22. mayaVersion = mel.eval('getApplicationVersionAsFloat')
  23.  
  24. # get maya main window via MEL
  25. gMainWindow = mel.eval('$tmpVar=$gMainWindow')
  26.  
  27.  
  28. def menuSetup(parent=gMainWindow):
  29.     """
  30.    This method handles adding the relevant menu items to Maya's
  31.    main menubar for the user to select tools
  32.    :param parent: string
  33.    :return:
  34.    """
  35.  
  36.     # check if menu root already exists and delete it
  37.     if mc.menu('rigToolsSTKMenuItemRoot', exists=True):
  38.         mc.deleteUI('rigToolsSTKMenuItemRoot')
  39.         log.info('Rebuilding Existing RigTools Menu')
  40.  
  41.     # check if main MayaWindow exists as a window object
  42.     if mc.window( parent, exists=True ):
  43.  
  44.         # is there menubar enabled for the MayaWindow?
  45.         if not mc.window( parent, q=True, menuBar=True ):
  46.             raise StandardError('given parent for RigTools Menu has no '
  47.                                 'menuBarlayout {0}'.format(parent) )
  48.  
  49.         else:
  50.             # add the menu root to the MayaWindow menubar
  51.             mc.menu( 'rigToolsSTKMenuItemRoot', l="RigTools", p=parent,
  52.                     tearOff=True, allowOptionBoxes=True )
  53.             log.info('new RigTools Menu added to current window : {0}'.format(parent) )
  54.  
  55.     # check if MayaWindow exists as a menu object instead, then add as submenu
  56.     elif mc.menu( parent, exists=True ):
  57.         mc.menuItem( 'rigToolsSTKMenuItemRoot', l='RigTools', sm=True, p=parent )
  58.         log.info('new RigTools subMenu added to current Menu : {0}'.format(parent) )
  59.  
  60.     else:
  61.         raise StandardError('given parent for RigTools Menu is invalid : {0}'.format(parent) )
  62.  
  63.     try:
  64.  
  65.         # add the main menu items
  66.         # Rigging util menu
  67.         mc.menuItem( 'rigToolsSTKRiggingCat', l='Rigging', sm=True, to=True, allowOptionBoxes=True,
  68.                      ann='Rigging utilities', p='rigToolsSTKMenuItemRoot' )
  69.  
  70.         # create reference locators
  71.         mc.menuItem('rigToolsSTKRigging_createRefLocs', l='Create ref. locators',
  72.                     ann='Creates a special locator at selected object positions for reference',
  73.                     p='rigToolsSTKRiggingCat', ec=True,
  74.                     c='from rigTools.tools.tools import createRefLoc;createRefLoc()' )
  75.  
  76.         # create reference locators options
  77.         mc.menuItem( optionBox=True,
  78.                      ann='Options for creating reference locators',
  79.                      p='rigToolsSTKRiggingCat', ec=True,
  80.                      c='pass')
  81.  
  82.         # del. reference locators
  83.         mc.menuItem('rigToolsSTKRigging_delRefLocs', l='Del. ref. locators',
  84.                     ann='Delete all reference locators',
  85.                     p='rigToolsSTKRiggingCat', ec=True,
  86.                     c='from rigTools.tools.tools import delAllRefLocs;delAllRefLocs()' )
  87.  
  88.         mc.menuItem( divider=True, p='rigToolsSTKRiggingCat' )
  89.  
  90.         # grpFrz
  91.         mc.menuItem('rigToolsSTKRigging_groupFreeze', l='Group freeze',
  92.                     ann='Creates an intermediate group xform and sets selected objects to identity xform',
  93.                     p='rigToolsSTKRiggingCat', ec=True,
  94.                     c='from rigTools.tools.tools import grpFrz;grpFrz()' )
  95.  
  96.         # Rename objects
  97.         mc.menuItem('rigToolsSTKRigging_renameObjs', l='Rename objects',
  98.                     ann='Renames the selected objects according to naming convention',
  99.                     p='rigToolsSTKRiggingCat', ec=True,
  100.                     c='pass' )
  101.  
  102.         # change object colours
  103.         mc.menuItem('rigToolsSTKRigging_changeColour', l='Change colours',
  104.                     ann='Re-colors the selected objects',
  105.                     p='rigToolsSTKRiggingCat', ec=True,
  106.                     c='pass' )
  107.  
  108.         # create object colour options
  109.         mc.menuItem( optionBox=True,
  110.                      ann='Options for changing object colours',
  111.                      p='rigToolsSTKRiggingCat', ec=True,
  112.                      c='pass')
  113.  
  114.         # match pivots
  115.         mc.menuItem('rigToolsSTKRigging_matchPivots', l='Match pivots',
  116.                     ann='Matches the pivots of the 2nd to the 1st selected object',
  117.                     p='rigToolsSTKRiggingCat', ec=True,
  118.                     c='from rigTools.tools.tools import matchPivots;matchPivots()' )
  119.  
  120.         # match xforms
  121.         mc.menuItem('rigToolsSTKRigging_matchXform', l='Match transformations',
  122.                     ann='Matches the transformations of the 2nd to the 1st selected `object',
  123.                     p='rigToolsSTKRiggingCat', ec=True,
  124.                     c='from rigTools.tools.tools import matchXForm;matchXForm()' )
  125.  
  126.         # create null grp
  127.         mc.menuItem('rigToolsSTKRigging_createNullGrp', l='Create null group',
  128.                     ann='Create null transform groups at the selected objects',
  129.                     p='rigToolsSTKRiggingCat', ec=True,
  130.                     c='from rigTools.tools.tools import createNullGrp;createNullGrp()' )
  131.  
  132.         mc.menuItem( divider=True, p='rigToolsSTKRiggingCat' )
  133.  
  134.         # generate controls
  135.         mc.menuItem('rigToolsSTKRigging_createControls', l='Create controls',
  136.                     ann='Create controls for the selected objects',
  137.                     p='rigToolsSTKRiggingCat', ec=True,
  138.                     c='pass' )
  139.  
  140.         # generate controls options
  141.         mc.menuItem( optionBox=True,
  142.                      ann='Options for creating control objects',
  143.                      p='rigToolsSTKRiggingCat', ec=True,
  144.                      c='pass')
  145.  
  146.         # reset skinned joints
  147.         mc.menuItem('rigToolsSTKRigging_resetSkinnedJoints', l='Reset skinned joints',
  148.                     ann='Reset skin deformation for the selected joint(s)',
  149.                     p='rigToolsSTKRiggingCat', ec=True,
  150.                     c='from rigTools.tools.tools import resetSkinnedJoints;resetSkinnedJoints()' )
  151.  
  152.         # curve utils
  153.         mc.menuItem('rigToolsSTKRigging_curveUtils', l='Curve Utils.', to=True, sm=True,
  154.                     ann='Utilities for NURBS curves',
  155.                     p='rigToolsSTKRiggingCat' )
  156.  
  157.         # make selected curves dynamic
  158.         mc.menuItem('rigToolsSTKRigging_makeSelectedCurvesDynamic', l='Make sel. curves dynamic',
  159.                     ann='Make the selected NURBS curves dynamic (nHair)',
  160.                     p='rigToolsSTKRigging_curveUtils', ec=True,
  161.                     c='from rigTools.tools.tools import makeSelectedCurvesDynamic;'
  162.                       'makeSelectedCurvesDynamic()' )
  163.  
  164.         # autorigger from curve guide
  165.         mc.menuItem('rigToolsSTKRigging_makeCurveAutorig', l='Curve Autorigger',
  166.                     ann='Generate a control rig using a NURBS curve as a guide',
  167.                     p='rigToolsSTKRigging_curveUtils',
  168.                     c='pass' )
  169.  
  170.         # Geo utilities menu
  171.         mc.menuItem( 'rigToolsSTKGeoCat', l='Geo. utilities', sm=True, to=True, allowOptionBoxes=True,
  172.                      ann='Geometry utilities', p='rigToolsSTKMenuItemRoot' )
  173.  
  174.         # del. extra UV sets
  175.         mc.menuItem('rigToolsSTKGeo_delExtraUvSets', l='Del. extra UV sets',
  176.                     ann='Deletes all but the first UV set from an object',
  177.                     p='rigToolsSTKGeoCat', ec=True,
  178.                     c='from rigTools.tools.tools import delExtraUvSets;delExtraUvSets()' )
  179.  
  180.         # anim utils menu
  181.         mc.menuItem( 'rigToolsSTKAnimCat', l='Anim. utilities', sm=True, to=True, allowOptionBoxes=True,
  182.                      ann='Animation  utilities', p='rigToolsSTKMenuItemRoot' )
  183.  
  184.         # set anim tangent prefs
  185.         mc.menuItem('rigToolsSTKAnim_setGlobalAnimTangents', l='Set anim. tangents',
  186.                     ann='Set the type of animation tangents globally',
  187.                     p='rigToolsSTKAnimCat', sm=True, to=True )
  188.  
  189.         # stepped tangents
  190.         mc.menuItem('rigToolsSTKAnim_setGlobalAnimTangents_step', l='Stepped',
  191.                     ann='Set tangents to Stepped mode',
  192.                     p='rigToolsSTKAnim_setGlobalAnimTangents', ec=True,
  193.                     c="from rigTools.tools.tools import setAnimTangents; setAnimTangents('step')" )
  194.  
  195.         # linear tangents
  196.         mc.menuItem('rigToolsSTKAnim_setGlobalAnimTangents_linear', l='Linear',
  197.                     ann='Set tangents to Linear mode',
  198.                     p='rigToolsSTKAnim_setGlobalAnimTangents', ec=True,
  199.                     c="from rigTools.tools.tools import setAnimTangents; setAnimTangents('linear')" )
  200.  
  201.         # auto tangents
  202.         mc.menuItem('rigToolsSTKAnim_setGlobalAnimTangents_auto', l='Auto',
  203.                     ann='Set tangents to Auto mode',
  204.                     p='rigToolsSTKAnim_setGlobalAnimTangents', ec=True,
  205.                     c="from rigTools.tools.tools import setAnimTangents; setAnimTangents('auto')" )
  206.  
  207.         # anim pose menu
  208.         mc.menuItem('rigToolsSTKAnim_PoseCat', l='Pose management',
  209.                     ann='Various utilities to deal with poses',
  210.                     p='rigToolsSTKAnimCat', sm=True, to=True )
  211.  
  212.         # save pose
  213.         mc.menuItem('rigToolsSTKAnim_savePose', l='Save pose',
  214.                     ann="Save all selected objects' pose at current frame",
  215.                     p='rigToolsSTKAnim_PoseCat', ec=True,
  216.                     c="pass" )
  217.  
  218.         # load pose
  219.         mc.menuItem('rigToolsSTKAnim_loadPose', l='Load pose',
  220.                     ann="Load poses back onto the selected objects (overwrites current keyframe)",
  221.                     p='rigToolsSTKAnim_PoseCat', ec=True,
  222.                     c="pass" )
  223.  
  224.         # FBX split exporter
  225.         mc.menuItem('rigToolsSTKAnimFBXSplitExporter', l='FBX Split Exporter',
  226.                     ann='A tool used for animation take management and export to FBX format',
  227.                     p='rigToolsSTKAnimCat', ec=True,
  228.                      c='try:reload(natUi)\nexcept:import python.dev.rigTools.stk_naAnimTools as natUi;\n'
  229.                        'natUi.show()' )
  230.  
  231.         mc.menuItem( divider=True, p='rigToolsSTKMenuItemRoot' )
  232.  
  233.         # full UI
  234.         mc.menuItem( 'rigToolsSTKUi', l='Launch full UI',
  235.                      ann='Launch full UI and dock to sidebar', p='rigToolsSTKMenuItemRoot', ec=True,
  236.                      c='try:reload(rigToolsUi)\nexcept:import python.dev.rigTools.stk_rigTools as rigToolsUi;\n'
  237.                        'rigToolsUi.show()')
  238.  
  239.         log.info('Successfully populated the RigTools menu!')
  240.  
  241.     except:
  242.         raise StandardError('Unable to parent RigToolsSTK Menu to given parent {0}'.format(parent) )
  243.  
  244.  
  245. def start():
  246.     """
  247.    This method is the entry point for the Rig Tools Menu.
  248.    Call this to initalize the setup of the entire toolset into Maya's UI.
  249.    :return:
  250.    """
  251.  
  252.     #log.info('Rig Tools being loaded from : {0}'.format(rigToolsModulePath) )
  253.  
  254.     try:
  255.         # add menu and menuItems to main MayaWindow menubar
  256.         menuSetup(parent=gMainWindow)
  257.  
  258.     except:
  259.         log.debug('RigTools STK main menu build failed!!!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement