# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import shelfButton [as 别名]
def createShelfButton(command, label='', name=None, description='',
image=None, #the default image is a circle
labelColor=(1, 0.5, 0),
labelBackgroundColor=(0, 0, 0, 0.5),
backgroundColor=None
):
'''
Create a shelf button for the command on the current shelf
'''
#some good default icons:
#menuIconConstraints - !
#render_useBackground - circle
#render_volumeShader - black dot
#menuIconShow - eye
gShelfTopLevel = mm.eval('$temp=$gShelfTopLevel')
if not mc.tabLayout(gShelfTopLevel, exists=True):
OpenMaya.MGlobal.displayWarning('Shelf not visible.')
return
if not name:
name = label
if not image:
image = getIcon(name)
if not image:
image = 'render_useBackground'
shelfTab = mc.shelfTabLayout(gShelfTopLevel, query=True, selectTab=True)
shelfTab = gShelfTopLevel+'|'+shelfTab
#add additional args depending on what version of maya we're in
kwargs = {}
if MAYA_VERSION >= 2009:
kwargs['commandRepeatable'] = True
if MAYA_VERSION >= 2011:
kwargs['overlayLabelColor'] = labelColor
kwargs['overlayLabelBackColor'] = labelBackgroundColor
if backgroundColor:
kwargs['enableBackground'] = bool(backgroundColor)
kwargs['backgroundColor'] = backgroundColor
return mc.shelfButton(parent=shelfTab, label=name, command=command,
imageOverlayLabel=label, image=image, annotation=description,
width=32, height=32, align='center', **kwargs)