"Create"
flag is only relevant when first running the command, such as when you initially create a polygonal primitive eg: Create a Cube Command myCube = cmds.polyCube()
"Query"
flag can be queried after the command has been run and can be used to retrieve information about something in the scene eg: Use the query mode to store the new number of divisions to a variable numOfDivisions = cmds.polyCube(myCube, query=True, subdivisionsX=True)
print(numOfDivisions)
# You should see "5.0" as the output.
"Edit"
flag can be edited after the fact eg: Change the X subdivisions from the cube we created cmds.polyCube(myCube, edit=True, subdivisionsX = 5)
"Multiple"
flag can be used more than once in a single instance of the command (for example, to create specify multiple points when creating a curve)import sys
pathList = sys.path
for path in pathList:
print(path)
create a python script
import sys
sys.path.append('directory path')
Let maya execute script everytime when runing the program, what we need to do is to save this file in
Mac:
~/Library/Preference/Autodesk/maya/<version>/scripts
Windows:
<drive>:\Documents and Settings\<username>\My Documents\maya<version>\scripts
When we want to runing an external script in maya, First thing is to make sure the script is in maya script folder, on Windows, it can be found in <drive>:\Documents and Settings\<username>\My Documents\maya<version>\scripts
, on Mac can be found in ~/Library/Preference/Autodesk/maya/<version>/scripts
when import the script make sure to use reload() function to clear the caches.
import maya.cmds as cmds
print("Imported the script!")
def makeObject():
cmds.polyCube()
print("Made a cube!")
import myScript
reload(myScript)
myScript.makeObject()
Maya offers two different languages with which to create custom functionality via scripting—both Maya Embedded Language (MEL
) scripts and Python
. Normally we only want to use one of them, but some times we can call the mel script through python.
1.Create a Mel File add following:
global proc myMELScript()
{
polyCube;
print("Hello from MEL!");
}
2.Create a Python File add following:
import maya.cmds as cmds
import maya.mel as mel
def runMEL():
print("Running MEL from Python")
mel.eval("source myMELScript;")
mel.eval("myMELScript;")
runMEL()
3.Run it in maya with
import runMEL
reload(runMEL)
End –Cheng Gu