import maya.cmds as cm
import random as random
myList = cm.ls (sl = True)
class MovingObjects:
def up(*arg):
for objects in myList:
cm.move(0,0.5,0 ,r = True)
def down(*arg):
for objects in myList:
cm.move(0,-0.5,0 ,r = True)
class microMove(MovingObjects):
def microUp(*arg):
cm.move(0,0.1,0 , r = True)
def microDown(*arg):
cm.move(0,-0.1,0 , r = True)
class declare:
def transformDeclare(*arg):
for objects in myList:
print('%s'%objects)
print(cm.getAttr('%s.translateX'%objects))
print(cm.getAttr('%s.translateY'%objects))
print(cm.getAttr('%s.translateZ'%objects))
class randomTransform:
def Randomize(*arg):
for objects in myList:
cm.xform('%s'%objects , ws=True,t=[random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)])
M = MovingObjects()
D = declare()
mM = microMove()
RT = randomTransform()
cm.headsUpMessage('First: "please select objects"', verticalOffset=300)
cm.window(t = 'X-transform' , h = 150 , w = 500 , s = False)
cm.columnLayout()
cm.button(l = 'Up' , c = M.up , w = 300 , h = 50 , bgc = (0,0.7,0.7) )
cm.button(l = 'micro-Up' , c = mM.microUp , w = 300 , bgc = (0,1,1))
cm.button(l = 'micro-Down' , c = mM.microDown , w = 300 , bgc = (0,1,1))
cm.button(l = 'Down' , c = M.down , w = 300 , h = 50 , bgc = (0,0.7,0.7) )
cm.button(l = 'Randomizing-objects-transform' , h = 50 , w = 300 , c = RT.Randomize , bgc = (0.8,0.8,0))
cm.button(l = 'Transformation-info' , c = D.transformDeclare , w = 300 , h = 50 )
cm.text( label='Script by : Amin-khormaei', align='center' )
cm.showWindow()
cm.error('Hey dude.. this is it')
嘿伙计们,我有两个问题4你好吗?
1:最后一行cm.error('X')给我一个运行时错误
2:类声明仅适用于我第一次运行它,当我想获得刷新转换信息时我应该再次运行脚本
请帮助duuuudes。
最好的问候。答案 0 :(得分:0)
最后一行总是给你一个错误(有关更多信息,请参阅此链接 http://download.autodesk.com/global/docs/maya2013/en_us/CommandsPython/error.html)
答案 1 :(得分:0)
不是使用headsUpMessage()
而是使用更强大的东西,例如声明自己的错误类。这个link解释了很多关于这个主题的内容。
顺便说一下,你实际上并没有使用pymel,因此标记你的问题是不准确的。 maya.cmds只是用python包裹着。要使用pymel,你需要像这样导入:
from pymel.core import *