Maya Environment
​
1
Cam
2
opt + LMB - rotate
3
opt + RMB - scale
4
opt + MMB - move
5
6
Viewport
7
frame geometry - H
8
frame selected object - o
9
Show Attribute Editor - Ctrl + A
10
Settings
11
preferences -
12
Project -
13
Render -
14
15
Essential
16
Commander -
Copied!

Setting up Visual Studio Code for Maya

  1. 1.
    Install Python, Visual Studio Code
  2. 2.
    In VSC, install MEL - Maya Embedded Language, Maya-code, Maya-Py, Maya Code
  3. 3.
    Download latest devkit > copy devkit into dev kit folder in your Maya application folder
  4. 4.
    Modify your JSON
  5. 5.
    In Maya > Script Editor > Open ports by entering these code
1
import maya.cmds as cmds
2
# Open new ports
3
cmds.commandPort(name=":7001", sourceType="mel", echoOutput=True)
4
cmds.commandPort(name=":7002", sourceType="python", echoOutput=True)
Copied!
To enable ports at startup create a file named userSetup.mel in the following folder:
1
Windows: <drive>:\Documents and Settings\<username>\My Documents\maya\<Version>\scripts
2
Mac OS X: ~/Library/Preferences/Autodesk/maya/<version>/scripts.
3
Linux: ~/maya/<version>/scripts.
4
(where ~ is your home folder)
Copied!
In the userSetup.mel file add the following
1
commandPort -name "localhost:7001" -sourceType "mel" -echoOutput;
2
commandPort -name "localhost:7002" -sourceType "python" -echoOutput;
Copied!
1
{
2
"python.pythonPath": "python",
3
"python.autoComplete.extraPaths": [ "C:/Program Files/Autodesk/Maya2019/devkit/other/pymel/extras/completion/py" ],
4
​
5
}
Copied!
/Applications/Autodesk/maya2020/devkit
​

​Autodesk tuts​

Part 1: Creating and Manipulating Objects

  • open Script Editor to see echo MEL command
  • go to Help > Python reference
  • flags: ch,o,w,g,d,name
  • DAG - direct acyclic graphic: transform node>shape node > data structures
  • Window > Setting / Preferences > Preferences > Selection > Track Selection Order
Hotkeys
  • Cmd T - new python
keyRotation
aimAtFirst
randomInstances
randomCubes.py
1
import maya.cmds as cmds
2
​
3
def keyFullRotation(pObjectName,pStartTime, pEndTime, pTargetAttribute):
4
​
5
#print '%s type: %s' % (objectname, objectTypeResult)
6
cmds.cutKey(pObjectName, time=(pStartTime,pEndTime), attribute=pTargetAttribute)
7
cmds.setKeyframe(pObjectName, time= pStartTime, attribute = pTargetAttribute, value=0)
8
cmds.setKeyframe(pObjectName, time= pEndTime, attribute = pTargetAttribute, value=360)
9
10
#linear tangent
11
cmds.selectKey(pObjectName, time-(pStartTime,pEndTime), attribute = pTargetAttribute
12
cmds.keyTangent(inTangentType = 'linear', outTangetType='linear')
13
14
15
selectionList = cmds.ls(selection=True, type = 'transform))
16
​
17
if len(selectionList)>=1:
18
#print 'Selected items: %s' % (selectionList)
19
20
for objectName in selectionList:
21
22
startTime = cmds.playBackOptions(query=True,minTime=True)
23
endTime = cmds.playBackOptions(query=True,maxTime=True)
24
​
25
#objectTypeResult = cmds.objectType(objectName)
26
27
keyFullRotation(objectName, startTime,endTime,'rotateY')
28
else:
29
print ' Please select at least one object'
Copied!
1
#aimAtFirst.py
2
​
3
import maya.cmds. as cmds
4
selectionList = cmds.ls (orderedSelection = True)
5
​
6
if len(selectionList) >=2:
7
print 'Selected itesms: %s' %(selectionList)
8
targetName = SelecitonList[0]
9
selectionList.remove(targetName)
10
11
for objectName in SelectionList:
12
print 'Constraining %s towards %s' % (objectName, tartgetName)
13
cmds.aimConstraint(targetName, objetName, aimVector = [ 0,1,0])
14
​
15
else:
16
print 'Please select two or more objects.'
Copied!
1
#randomInstances.py
2
​
3
import maya.cmds as cmds
4
import random
5
​
6
random.seed(1234)
7
​
8
# selectionOrder
9
result = cmd.ls(orderedSelection = True)
10
print 'result: %s' % (result) # replace string technique
11
​
12
transformName = result[0]
13
# create a group
14
instanceGroupName = cmds.group(empty=True,name = transformName + '_instance_grp')
15
​
16
#instancing with for loop
17
for i in range(0,50):
18
​
19
instanceResult = cmds.instance(transformName, name = transformName + ' _instance#'
20
21
cmds.parent(instanceRsult,instanceGroupName)
22
x = random.uniform(10,10)
23
y = random.uniform(0,20)
24
z = random.uniform(-10,10)
25
​
26
cmds.move(x,y,z, instanceResult)
27
28
#randomize rotation
29
xRot= random.uniform (0,360)
30
yRot= random.uniform (0,360)
31
zRot= random.uniform (0,360)
32
cmds.rotation(xRot,yRot,zRot, instanceResult)
33
34
# randomize factor
35
scalingFactor = random.uniform(0.3, 1.5)
36
cmds.scale(scalingFactor, scalingFactor,scalingFactor, instanceResult)
37
​
38
# hide original cube & center pivit
39
cmds.hide(transformName)
40
cmds.xform(instanceGroupName, centerPiviots=True)
41
​
Copied!
1
#randomCubes.py
2
​
3
import maya.cmds as cmds
4
import random
5
​
6
random.seed(1234)
7
​
8
#commenting out multiple lines
9
'''
10
#fetch all objects who name starts with myCube + wildcard
11
cubeList = cmds.ls('myCube*')
12
​
13
#delete all cube items in cubeList
14
if (len(cubeList)) > 0:
15
cmds.delete(cubeList)
16
'''
17
18
result = cmds.polyCube(w=9,h=9,d=9, name = 'myCube#')
19
transformName = result[0]
20
# create a group
21
instanceGroupName = cmds.group(empty=True,name = transformName + '_instance_grp')
22
​
23
#instancing with for loop
24
for i in range(0,50):
25
​
26
instanceResult = cmds.instance(transformName, name = transformName + ' _instance#'
27
28
cmds.parent(instanceRsult,instanceGroupName)
29
x = random.uniform(10,10)
30
y = random.uniform(0,20)
31
z = random.uniform(-10,10)
32
​
33
cmds.move(x,y,z, instanceResult)
34
35
#randomize rotation
36
xRot= random.uniform (0,360)
37
yRot= random.uniform (0,360)
38
zRot= random.uniform (0,360)
39
cmds.rotation(xRot,yRot,zRot, instanceResult)
40
41
# randomize factor
42
scalingFactor = random.uniform(0.3, 1.5)
43
cmds.scale(scalingFactor, scalingFactor,scalingFactor, instanceResult)
44
​
45
# hide original cube & center pivit
46
cmds.hide(transformName)
47
cmds.xform(instanceGroupName, centerPiviots=True)
48
​
Copied!

​

Why

  • widespread
  • cross platform
  • cross-software

Troubleshooting

Modifying userSetup.mel

Mac: ~/Library/Preferences/Autodesk/maya/2020/scripts
​
​

​