Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Maya Python Snippets
import sys
devPath = '/Users/ev/Documents/projects/maya/'
if devPath not in sys.path: sys.path.insert(0, devPath)
for path in sys.path:
print path
from RGB.multiSnap.multiSnap import MultiSnap_ui
currentClassPath = sys.modules[MultiSnap_ui.__module__]
Simply creates a locator at each selected object
import maya.cmds as cmds
nodes =, type='transform')
for node in nodes:
pos = cmds.xform(node, q=True, t=True, ws=True)
loc = cmds.spaceLocator()
cmds.xform(loc, t=pos)
print("%s => %s" % (node, loc, pos))
# Create Select Command
import maya.cmds as cmds
nodes =, type='transform')
print(", r=True)" % (nodes))
#Open New Maya
from subprocess import call
appPath = "/Applications/Autodesk/maya2014/"
call(["open -n " + appPath], shell=True)
# Scale Given objects by value
import maya.cmds as cmds
def scaleMult(objs, mult):
sMtx = cmds.xform(objs,q=True, r=True, scale=True)
x = sMtx[0] * mult
y = sMtx[1] * mult
z = sMtx[2] * mult
cmds.xform(objs, scale=(x, y, z))
scaleMult("RRM_MAIN", 0.01)
# Return frame data
import maya.cmds as cmds
import maya.mel as mel
def get_fdata():
aPlayBackSliderPython = mel.eval('$tmpVar=$gPlayBackSlider')
selection =
selectionActvive = cmds.timeControl(aPlayBackSliderPython, query=True, rangeVisible=True)
range = cmds.timeControl(aPlayBackSliderPython, query=True, rangeArray=True)
fdata = {}
fdata['f'] = cmds.currentTime( query=True )
fdata['fs'] = cmds.playbackOptions(query=True, min=True)
fdata['fe'] = cmds.playbackOptions(query=True, max=True)
fdata['sf'] = selectionActvive
fdata['sfs'] = range[0]
fdata['sfe'] = range[1]
return fdata
import maya.cmds as cmds
def getSelectedChannels()
return cmds.channelBox('mainChannelBox', q=True, sma=True)
# Frame Selected PaintWeight Influences
import maya.cmds as cmds
curSel =
pwSelectedInfluences = maya.mel.eval("$temp=$gArtSkinOrderedInfluenceSelectionList"), r=True)
cmds.viewFit(), r=True)
fitPanel -selected;
animView -startTime (`playbackOptions -query -minTime` - 1) -endTime (`playbackOptions -query -maxTime` + 1) graphEditor1GraphEd;
# Frame Curve Editor
def frameGraphEditor():
fs = cmds.playbackOptions(q=True, minTime=True) - 1
fe = cmds.playbackOptions(q=True, maxTime=True) + 1
cmds.animView('graphEditor1GraphEd', startTime = fs, endTime = fe)
global proc gecco_insertKey () {
string $curves[] = `keyframe -q -sl -name`; // get all selected curves
float $time = `currentTime -q`; // get the current frame
for($i=0; $i < size($curves); $i++) {
setKeyframe -insert -time $time $curves[$i];
# Replaces "Add Key" functionality with more desired insertKey
import maya.cmds as cmds
def insertKey ():
curFrame = cmds.currentTime(query=True)
curves = cmds.keyframe(query=True, sl=True, name=True) or []
unkeyed = []
# If no keys/curves selected in graph editor, look to channel box selection
if len(curves) == 0:
objs = cmds.channelBox('mainChannelBox', query=True, mainObjectList=True) or []
attrs = cmds.channelBox('mainChannelBox', query=True, sma=True) or []
for obj in objs:
for attr in attrs:
attrFull = obj+'.'+attr
keyCount = cmds.keyframe(attrFull, query=True, keyframeCount=True )
if keyCount > f:
# Insert Key on curves with existing keys.
if len(curves) > 0:
cmds.setKeyframe(curves, insert=True, time=curFrame)
# Add key on attributes with no keys
if len(unkeyed) > 0:
cmds.setKeyframe(unkeyed, time=curFrame)
This script generates a nurbs curve object, from a given polygon object's edges
# Examples
## A) Entering Data Manually
poly2icon('myPolyObject', 'myNewIcon')
## B) Using first-selected object and prompting user for icon name
obj =[0]
poly2icon(obj, prompt4name())
import maya.cmds as cmds
def prompt4name():
result = cmds.promptDialog(
title='Name Your New Object',
message='Enter Name:',
button=['OK', 'Cancel'],
if result == 'OK':
return cmds.promptDialog(query=True, text=True)
def poly2icon(geom, newName):
name = ''
crvs = []
shapes = []
edgeCount = cmds.polyEvaluate(geom, edge=True)
objPivots = cmds.xform(geom, q=True, rp=True, ws=True)
# Create linear curves from edges
for idx in range(0, edgeCount):
edge = '%s.e[%s]' % (geom, idx)
crv = cmds.polyToCurve(edge, form = 0, degree =1)[0];
shape = cmds.listRelatives(crv, shapes=True)
# Parent all shapes under first shape
if idx > 0:
cmds.parent(shape, crvs[0], relative=True, shape=True)
name = crvs[0]
# Remove Useless Transform Nodes
for idx in range(1, edgeCount):
# Match Geom Pivot
cmds.xform(name, pivots=objPivots)
# Delete History
cmds.delete(name, ch=True)
# Name Object
if newName != "":
cmds.rename(name, newName)
name = newName
return name;
This fixes a RRM bug (v1.4.7) where saved RRM setups do not preserve a
module's 'pinned' status.
import maya.cmds as cmds
import maya.mel
def RRM_fixPinBug(objs):
for obj in objs:
trans = cmds.xform(obj,q=True, r=True, translation=True)
maya.mel.eval("RRM_PinProxies(1, 0);")
cmds.xform(obj, translation=trans)
maya.mel.eval("RRM_PinProxies(0, 1);")
#Example Usage
objs = selection=True )
This prints out a list of each RRM module which are currently pinned
# Check Pinned Status
import maya.cmds as cmds
import maya.mel
def RRM_selectParents():
parents = 'RRM*Parent' )
for obj in parents:
val = cmds.getAttr(obj + '.pinned')
print('%s : %s') % (obj, val)
// Timeslider
timeControl -edit -pressCommand "undoInfo -stateWithoutFlush off;" -releaseCommand "undoInfo -stateWithoutFlush on;" $gPlayBackSlider
// Hotkeys
// Next Frame (Alt + .)
undoInfo -stateWithoutFlush off;
currentTime ( `currentTime -q` + 1 );
undoInfo -stateWithoutFlush on;
// Previous frame (Alt + ,)
undoInfo -stateWithoutFlush off;
currentTime ( `currentTime -q` - 1 );
undoInfo -stateWithoutFlush on;
// Next Key (.)
undoInfo -stateWithoutFlush off;
currentTime -edit `findKeyframe -timeSlider -which next`;
undoInfo -stateWithoutFlush on;
// Previous Key (,)
undoInfo -stateWithoutFlush off;
currentTime -edit `findKeyframe -timeSlider -which previous`;
undoInfo -stateWithoutFlush on;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.