0
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。

最好的祝福。

4

2 回答 2

0

最后一行总是给你一个错误(有关更多信息,请参阅此链接 http://download.autodesk.com/global/docs/maya2013/en_us/CommandsPython/error.html

于 2013-07-12T10:42:06.540 回答
0

而不是使用headsUpMessage()I 会去一些更健壮的东西,比如声明你自己的错误类。这个链接解释了很多关于这个主题的内容。顺便说一句,您实际上并没有使用 pymel,因此这样标记您的问题是不准确的。maya.cmds 只是用 python 包裹的 mel。要使用 pymel,您需要像这样导入:

from pymel.core import *
于 2013-07-12T17:42:36.647 回答