Username
Password
Auto-login
Show my name in the online users list
Not a member?
Please register.
Forgot your password?
(2) October 2008
(6) September 2008
(7) August 2008
(6) July 2008
(9) June 2008
(4) May 2008
(6) April 2008
(6) March 2008
(4) February 2008
(5) January 2008
(8) December 2007
(4) November 2007
Python functions
Posted: Jan 24, 2007 - 04:39 PM
Category: Python
To illustrate a couple of the other things I like about python, I've prepared a heavily documented yet simple python code example:

# these first lines are comments - note the "#" at the beginning of the line
#
# first you need to import maya.cmds
# this makes them available through python
import maya.cmds as mc
# "as mc" means that maya commands will be in the "mc" namespace
# the equivalent to the MEL command "sphere" would be "mc.sphere()"
# you could do "import maya.cmds" by itself and then the equivalent
# command would be "maya.cmds.sphere()"
#
# now define the function
def helloMaya():
# in MEL you would have done "proc helloMaya(){"
# note that all subsequent lines in the function are indented - very important!
# use only tabs or spaces - mixing can lead to trouble
#
# next you can add help to the function
# I really like this about python
'''a simple function to say hello maya. a user will see
whatever you put here when they ask for help on the function '''
#
# now actually do something
print 'hello maya!'
# note the different quote characters and that we don't need to use ";"
# at the end of the line


Put this in a python tab in your script editor and execute it. Then try the following commands from the python command line or script editor:

helloMaya()

help(helloMaya)
In order to post any comments, you must be logged in!
  Posted by cpan  on  24 Jan, 2007  at  04:07 PM
heh, thanks Cory!
python looks like a great addition to maya !
now i'll definitely take a look into the API, thanks to it !

keep it up !
calin
 
Page 1 of 1 pages