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)
Python functions
In order to post any comments, you must be logged in!
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
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




