Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- # menu setup script for rig tools
- __author__ = 'Siew Yi Liang'
- import logging
- import maya.cmds as mc
- import maya.mel as mel
- # setup streamhandler
- logging.basicConfig()
- # create logger (creates StreamHandler with default Formatter and
- # adds it to the logger object
- log = logging.getLogger(__name__)
- log.setLevel(logging.INFO)
- # get the current maya version
- mayaVersion = mel.eval('getApplicationVersionAsFloat')
- # get maya main window via MEL
- gMainWindow = mel.eval('$tmpVar=$gMainWindow')
- def menuSetup(parent=gMainWindow):
- """
- This method handles adding the relevant menu items to Maya's
- main menubar for the user to select tools
- :param parent: string
- :return:
- """
- # check if menu root already exists and delete it
- if mc.menu('rigToolsSTKMenuItemRoot', exists=True):
- mc.deleteUI('rigToolsSTKMenuItemRoot')
- log.info('Rebuilding Existing RigTools Menu')
- # check if main MayaWindow exists as a window object
- if mc.window( parent, exists=True ):
- # is there menubar enabled for the MayaWindow?
- if not mc.window( parent, q=True, menuBar=True ):
- raise StandardError('given parent for RigTools Menu has no '
- 'menuBarlayout {0}'.format(parent) )
- else:
- # add the menu root to the MayaWindow menubar
- mc.menu( 'rigToolsSTKMenuItemRoot', l="RigTools", p=parent,
- tearOff=True, allowOptionBoxes=True )
- log.info('new RigTools Menu added to current window : {0}'.format(parent) )
- # check if MayaWindow exists as a menu object instead, then add as submenu
- elif mc.menu( parent, exists=True ):
- mc.menuItem( 'rigToolsSTKMenuItemRoot', l='RigTools', sm=True, p=parent )
- log.info('new RigTools subMenu added to current Menu : {0}'.format(parent) )
- else:
- raise StandardError('given parent for RigTools Menu is invalid : {0}'.format(parent) )
- try:
- # add the main menu items
- # Rigging util menu
- mc.menuItem( 'rigToolsSTKRiggingCat', l='Rigging', sm=True, to=True, allowOptionBoxes=True,
- ann='Rigging utilities', p='rigToolsSTKMenuItemRoot' )
- # create reference locators
- mc.menuItem('rigToolsSTKRigging_createRefLocs', l='Create ref. locators',
- ann='Creates a special locator at selected object positions for reference',
- p='rigToolsSTKRiggingCat', ec=True,
- c='from rigTools.tools.tools import createRefLoc;createRefLoc()' )
- # create reference locators options
- mc.menuItem( optionBox=True,
- ann='Options for creating reference locators',
- p='rigToolsSTKRiggingCat', ec=True,
- c='pass')
- # del. reference locators
- mc.menuItem('rigToolsSTKRigging_delRefLocs', l='Del. ref. locators',
- ann='Delete all reference locators',
- p='rigToolsSTKRiggingCat', ec=True,
- c='from rigTools.tools.tools import delAllRefLocs;delAllRefLocs()' )
- mc.menuItem( divider=True, p='rigToolsSTKRiggingCat' )
- # grpFrz
- mc.menuItem('rigToolsSTKRigging_groupFreeze', l='Group freeze',
- ann='Creates an intermediate group xform and sets selected objects to identity xform',
- p='rigToolsSTKRiggingCat', ec=True,
- c='from rigTools.tools.tools import grpFrz;grpFrz()' )
- # Rename objects
- mc.menuItem('rigToolsSTKRigging_renameObjs', l='Rename objects',
- ann='Renames the selected objects according to naming convention',
- p='rigToolsSTKRiggingCat', ec=True,
- c='pass' )
- # change object colours
- mc.menuItem('rigToolsSTKRigging_changeColour', l='Change colours',
- ann='Re-colors the selected objects',
- p='rigToolsSTKRiggingCat', ec=True,
- c='pass' )
- # create object colour options
- mc.menuItem( optionBox=True,
- ann='Options for changing object colours',
- p='rigToolsSTKRiggingCat', ec=True,
- c='pass')
- # match pivots
- mc.menuItem('rigToolsSTKRigging_matchPivots', l='Match pivots',
- ann='Matches the pivots of the 2nd to the 1st selected object',
- p='rigToolsSTKRiggingCat', ec=True,
- c='from rigTools.tools.tools import matchPivots;matchPivots()' )
- # match xforms
- mc.menuItem('rigToolsSTKRigging_matchXform', l='Match transformations',
- ann='Matches the transformations of the 2nd to the 1st selected `object',
- p='rigToolsSTKRiggingCat', ec=True,
- c='from rigTools.tools.tools import matchXForm;matchXForm()' )
- # create null grp
- mc.menuItem('rigToolsSTKRigging_createNullGrp', l='Create null group',
- ann='Create null transform groups at the selected objects',
- p='rigToolsSTKRiggingCat', ec=True,
- c='from rigTools.tools.tools import createNullGrp;createNullGrp()' )
- mc.menuItem( divider=True, p='rigToolsSTKRiggingCat' )
- # generate controls
- mc.menuItem('rigToolsSTKRigging_createControls', l='Create controls',
- ann='Create controls for the selected objects',
- p='rigToolsSTKRiggingCat', ec=True,
- c='pass' )
- # generate controls options
- mc.menuItem( optionBox=True,
- ann='Options for creating control objects',
- p='rigToolsSTKRiggingCat', ec=True,
- c='pass')
- # reset skinned joints
- mc.menuItem('rigToolsSTKRigging_resetSkinnedJoints', l='Reset skinned joints',
- ann='Reset skin deformation for the selected joint(s)',
- p='rigToolsSTKRiggingCat', ec=True,
- c='from rigTools.tools.tools import resetSkinnedJoints;resetSkinnedJoints()' )
- # curve utils
- mc.menuItem('rigToolsSTKRigging_curveUtils', l='Curve Utils.', to=True, sm=True,
- ann='Utilities for NURBS curves',
- p='rigToolsSTKRiggingCat' )
- # make selected curves dynamic
- mc.menuItem('rigToolsSTKRigging_makeSelectedCurvesDynamic', l='Make sel. curves dynamic',
- ann='Make the selected NURBS curves dynamic (nHair)',
- p='rigToolsSTKRigging_curveUtils', ec=True,
- c='from rigTools.tools.tools import makeSelectedCurvesDynamic;'
- 'makeSelectedCurvesDynamic()' )
- # autorigger from curve guide
- mc.menuItem('rigToolsSTKRigging_makeCurveAutorig', l='Curve Autorigger',
- ann='Generate a control rig using a NURBS curve as a guide',
- p='rigToolsSTKRigging_curveUtils',
- c='pass' )
- # Geo utilities menu
- mc.menuItem( 'rigToolsSTKGeoCat', l='Geo. utilities', sm=True, to=True, allowOptionBoxes=True,
- ann='Geometry utilities', p='rigToolsSTKMenuItemRoot' )
- # del. extra UV sets
- mc.menuItem('rigToolsSTKGeo_delExtraUvSets', l='Del. extra UV sets',
- ann='Deletes all but the first UV set from an object',
- p='rigToolsSTKGeoCat', ec=True,
- c='from rigTools.tools.tools import delExtraUvSets;delExtraUvSets()' )
- # anim utils menu
- mc.menuItem( 'rigToolsSTKAnimCat', l='Anim. utilities', sm=True, to=True, allowOptionBoxes=True,
- ann='Animation utilities', p='rigToolsSTKMenuItemRoot' )
- # set anim tangent prefs
- mc.menuItem('rigToolsSTKAnim_setGlobalAnimTangents', l='Set anim. tangents',
- ann='Set the type of animation tangents globally',
- p='rigToolsSTKAnimCat', sm=True, to=True )
- # stepped tangents
- mc.menuItem('rigToolsSTKAnim_setGlobalAnimTangents_step', l='Stepped',
- ann='Set tangents to Stepped mode',
- p='rigToolsSTKAnim_setGlobalAnimTangents', ec=True,
- c="from rigTools.tools.tools import setAnimTangents; setAnimTangents('step')" )
- # linear tangents
- mc.menuItem('rigToolsSTKAnim_setGlobalAnimTangents_linear', l='Linear',
- ann='Set tangents to Linear mode',
- p='rigToolsSTKAnim_setGlobalAnimTangents', ec=True,
- c="from rigTools.tools.tools import setAnimTangents; setAnimTangents('linear')" )
- # auto tangents
- mc.menuItem('rigToolsSTKAnim_setGlobalAnimTangents_auto', l='Auto',
- ann='Set tangents to Auto mode',
- p='rigToolsSTKAnim_setGlobalAnimTangents', ec=True,
- c="from rigTools.tools.tools import setAnimTangents; setAnimTangents('auto')" )
- # anim pose menu
- mc.menuItem('rigToolsSTKAnim_PoseCat', l='Pose management',
- ann='Various utilities to deal with poses',
- p='rigToolsSTKAnimCat', sm=True, to=True )
- # save pose
- mc.menuItem('rigToolsSTKAnim_savePose', l='Save pose',
- ann="Save all selected objects' pose at current frame",
- p='rigToolsSTKAnim_PoseCat', ec=True,
- c="pass" )
- # load pose
- mc.menuItem('rigToolsSTKAnim_loadPose', l='Load pose',
- ann="Load poses back onto the selected objects (overwrites current keyframe)",
- p='rigToolsSTKAnim_PoseCat', ec=True,
- c="pass" )
- # FBX split exporter
- mc.menuItem('rigToolsSTKAnimFBXSplitExporter', l='FBX Split Exporter',
- ann='A tool used for animation take management and export to FBX format',
- p='rigToolsSTKAnimCat', ec=True,
- c='try:reload(natUi)\nexcept:import python.dev.rigTools.stk_naAnimTools as natUi;\n'
- 'natUi.show()' )
- mc.menuItem( divider=True, p='rigToolsSTKMenuItemRoot' )
- # full UI
- mc.menuItem( 'rigToolsSTKUi', l='Launch full UI',
- ann='Launch full UI and dock to sidebar', p='rigToolsSTKMenuItemRoot', ec=True,
- c='try:reload(rigToolsUi)\nexcept:import python.dev.rigTools.stk_rigTools as rigToolsUi;\n'
- 'rigToolsUi.show()')
- log.info('Successfully populated the RigTools menu!')
- except:
- raise StandardError('Unable to parent RigToolsSTK Menu to given parent {0}'.format(parent) )
- def start():
- """
- This method is the entry point for the Rig Tools Menu.
- Call this to initalize the setup of the entire toolset into Maya's UI.
- :return:
- """
- #log.info('Rig Tools being loaded from : {0}'.format(rigToolsModulePath) )
- try:
- # add menu and menuItems to main MayaWindow menubar
- menuSetup(parent=gMainWindow)
- except:
- log.debug('RigTools STK main menu build failed!!!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement