第一个maya的python脚本,比较简单,实现的功能是改变选中物体线框的颜色.
import maya.cmds as py
import sys
if py.window('pyColor',ex=True):
py.deleteUI('pyColor',wnd=True)
version = sys.version
print version
def resetButton(arg):
print 'reset was pushed.'
mySel = py.ls(sl=True)
if len(mySel)==0:
py.confirmDialog(t='提示',m='No object is selected!',b='OK')
else:
py.pickWalk(d='down')
mySel = py.ls(sl=True)
for item in mySel:
py.setAttr (item+".overrideEnabled",0)
py.setAttr (item+".overrideColor",0)
def note(arg):
mySel = py.ls(sl=True)
if len(mySel)==0:
py.confirmDialog(t='提示',m='No object is selected!',b='OK')
else:
colorObject(arg)
def colorObject(arg):
value = py.textField('input',q=True,tx=True)
py.pickWalk(d='down')
mySel = py.ls(sl=True)
for mySel in mySel:
py.setAttr (mySel+".overrideEnabled",1)
py.setAttr (mySel+".overrideColor",int(value))
if py.window('pyColor',ex=True):
py.deleteUI('pyColor',wnd=True)
py.window('pyColor',t='colorCurve')
py.columnLayout(adj=True)
py.text(l='请输入0到31的整数:',fn='fixedWidthFont',bgc=(0,0,0))
py.textField('input',tx='0',bgc=(0,0,0))
py.button(l='着色',c=note)
py.button(l='reset',c=resetButton)
py.showWindow()
结果截图: