Table of Contents

Intro - Maya in Python

Before you read anything below, read this list first

Intro to Maya API concepts

Directed Acyclic Graph (DAG)

DAG Path

Dependency nodes

DAG hierarchy nodes vs Dependency Graph (DG) nodes

DG node creation

DG node attribute

DG node data

DG shader node

DG shader node type

note: shader=material

DG shader node creation

DG shape node

DG deformer node

DG shape - polygon API

Maya in command line

maya flags

-v version number
-batch start in batch mode
-prompt non-gui mode
-proj [dir] start in define project
-command [mel] start with defined mel command
-script [mel] start with mel script file
-recover recovers last file
-render [file] render defined file
-archive [file] list required or related files to archive a scene
-help display flags help
-noAutoloadPlugins don't load any plugin

Preference

Viewport

Maya UI automation scripting

mel name python name description
$gChannelBoxName mainChannelBox channel box
$gCommandReporter cmdScrollFieldReporter1 script editor result panel
$gMainWindow MayaWindow maya main window
graph1HyperShadeEd graph1HyperShadeEd material hypershade
nodeEditorPanel2NodeEditorEd nodeEditorPanel2NodeEditorEd node editor

Hotkey

Note: from Maya 2017 onwards, you need to duplicate default maya hotkey to be able to make changes, it is under Windows > Settings > Hotkey Editor

Object Level API Process

Python Maya API reference

common api page offical reference page

DAG path, object and nodes

om.MDagPath:

om.MObject:

MFnDagNode:

import maya.OpenMaya as om
selected = om.MSelectionList()
om.MGlobal.getActiveSelectionList(selected)
dagPath = om.MDagPath()
selected.getDagPath(0,dagPath)
print(dagPath.fullPathName()) # current full path name
print(dagPath.partialPathName()) # current node name
 
# get shape count
countUtil = om.MScriptUtil()
countUtil.createFromInt(0)
tmpIntPtr = countUtil.asUintPtr() # unsigned int
dagPath.numberOfShapesDirectlyBelow(tmpIntPtr)
print(countUtil.getUint(tmpIntPtr))
print(dagPath.childCount()) # another alternative method
 
# get its Shape as MDagPath
dagPath.extendToShape() # MDagPath: change to shape path, will error if has no shape or more than 1 shape
dagPath.extendToShapeDirectlyBelow(0) # same as above; but won't error when more than 1 shape
print(dagPath.fullPathName()) # shape, if already shape, also return itself
 
# get itself as Node
dagObj = dagPath.node() # MObject
dagObj.hasFn(om.MFn.kDagNode) # check if its DAG node, not DG node
dagNode = om.MFnDagNode(dagObj) # use function to handle this MObject
print(dagNode.fullPathName())
 
# get its Transform as Node
dagObj = dagPath.transform() # MObject: return its transform MObject, if already transform, it return itself
dagNode = om.MFnDagNode(dagObj)
print(dagNode.fullPathName()) # transform node full dag path

DG nodes

other common class:

MPlugs and Attributes

ref: http://docs.autodesk.com/MAYAUL/2014/ENU/Maya-API-Documentation/index.html?url=cpp_ref/class_m_plug.html,topicNumber=cpp_ref_class_m_plug_html71ba8eb6-cc15-4382-8b6f-36cdfbc2ccc5

Array in MPlug:

Logical Index and Physical Index of Joint in skincluster

Concept of Dynamic array - a pre-defined-size list with pre-loaded empty items

The Physical index of joint in the influence list

Math Node before Calculation with API

Transform, Vector, Matrix, Quaternion, Angular Math

Selection in API

Modeling in Python vs Mel

# mel: DeleteHistory;
cmds.DeleteHistory()
 
# show poly vertex
# mel: setPolygonDisplaySettings("verts");
cmds.polyOptions(r=1, activeObjects=1, dv=1)
 
# mel: ToggleFaceNormalDisplay;
cmds.ToggleFaceNormalDisplay()
 
# mel: ToggleBackfaceGeometry;
cmds.ToggleBackfaceGeometry()
 
# mel: ReversePolygonNormals;
cmds.ReversePolygonNormals()
 
# hard edge
# mel: SoftPolyEdgeElements(0);
cmds.polySoftEdge(a=0)
 
# show border
# mel: ToggleBorderEdges;
cmds.ToggleBorderEdges()
 
# dialog to change edge width display
# mel: ChangeEdgeWidth;
cmds.ChangeEdgeWidth()
 
# show UV window
# mel: TextureViewWindow;
cmds.TextureViewWindow();
# mel: CenterPivot;
cmds.CenterPivot()
 
# turn on / off symmetric modeling
'''
symmetricModelling -e -symmetry true;symmetricModelling -e -symmetry false;
symmetricModelling -e -about "world";
symmetricModelling -e -about "object";
symmetricModelling -e -axis "x"
'''
cmds.symmetricModelling(e=1, symmetry=1)
cmds.symmetricModelling(e=1, symmetry=0)
 
# face selection to edge border selection
# mel: select -r `polyListComponentConversion -ff -te -bo`;
cmds.select(cmds.polyListComponentConversion(ff=1, te=1, bo=1),r=1)
 
# selection to shell
# mel: ConvertSelectionToShell;
cmds.ConvertSelectionToShell()
 
# selection to create layer
'''
string $tmpname[]=`ls -sl`;
createDisplayLayer -name ($tmpname[0]+"_Lyr") -number 1 -nr;
'''
selected = cmds.ls(sl=1)
if len(selected)>0:
    cmds.createDisplayLayer(name=selected[0]+'_layer', number=1, nr=1)
 
# remove from layers
# mel: editDisplayLayerMembers -noRecurse "defaultLayer" `ls -sl`
cmds.editDisplayLayerMembers("defaultLayer", cmds.ls(sl=1), noRecurse=1)
 
 
#### curve #####
 
# show CV
# mel: ToggleCVs;
cmds.ToggleCVs()
 
# show editable point
# mel: ToggleEditPoints;
cmds.ToggleEditPoints()
 
# rebuild curve dialog
# mel: RebuildCurveOptions;
cmds.RebuildCurveOptions()
 
# detach surface by edge or isopam
# mel: DetachCurve;
cmds.DetachCurve()
 
# detach/attach curve by cut
# mel: CutCurve; AttachCurve;
cmds.CutCurve()
cmds.AttachCurve()

Modeling in API

Vertex check in API way

Vertex Check

Face Check and Correct

Curve related

UV Editing

Material

Rigging

delete unknown nodes

common node and attributes

obj_transform .worldMatrix

Prefix remover

alias attribute

weight

Blendshape

* API: Geometry result deformed vertex list position info

pos_list = []
geo_iter = om.MItGeometry(obj_list[0])
while not geo_iter.isDone():
    p = geo_iter.position()
    pos_list.append((p.x, p.y, p.z))
    geo_iter.next()

Animation

Import and Export animation with atom plugin

Import and Export animation with Maya built-in file import export

Get all Animation Curve

Clean Static Animation on object

Bake Animation

Animation Cache

Camera and Viewport calculation

Render Related

Pipeline

Batch File Process Example

Scripting

Utility

Plugin

Maya Qt GUI Tool Development

My Python Tool

3rd Party Tool

Python and Maya Qt interface

PyQt case code

Environment setup

Environment of Python in Maya

Python in mel basic

Common Python function

RnD List

Angle Calculation

Proof of cos(A+B) formula

Proof of rotation matrix

understand Matrix multiplication

Vector calculation

Plane Intersection calcuation

Math tutorial links

Local space and World space and Screen space

Fluid Calculation model

3D Camera model

VR rendering in 3D