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

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.

Amin Khormaei
  • 379
  • 3
  • 8
  • 23

2 Answers2

0

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)

Linh Nguyen
  • 925
  • 1
  • 10
  • 23
  • i wanna show a message in command line for starting this script in maya. one guy told me that it's possible by error command. if it has a different method for doing this,please tell me. – Amin Khormaei Jul 12 '13 at 13:30
  • Well there are a couple of ways to do this..one would be to import sys, then you can use sys.stdout.write("This is output")...that would show up in the output bar towards the bottom. A print statement cannot do that. Another thing you could do is to put a print statement in your userSetup.py..this will print messages to your terminal or CMDPrompt on Windows... – Argiri Kotsaris Jul 12 '13 at 15:19
0

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 *
Argiri Kotsaris
  • 492
  • 3
  • 7