Question

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') 

hey guys i have two questions 4 ya ?

1: the last line cm.error('X') gets me a runtime error

2: class declare works just just for first time that i run it, when i wanna get the refresh transformation info i should run the script again

please help duuuudes.

best regards.

Was it helpful?

Solution

The last line always give you an error (for more information, plz refer this link http://download.autodesk.com/global/docs/maya2013/en_us/CommandsPython/error.html)

OTHER TIPS

Instead of using the headsUpMessage() I would go for something a little more robust such as declaring your own error class. This link explains a lot about that subject. And btw, you aren't actually using pymel so it is inaccurate to tag your question as such. maya.cmds is just mel wrapped in python. To use pymel you'll want to import like this:

from pymel.core import *
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top