-
-
Save rjmoggach/f68bda6ba4f312950d8ef2bb6f260195 to your computer and use it in GitHub Desktop.
Maya Python Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Simply creates a locator at each selected object | |
''' | |
import maya.cmds as cmds | |
nodes = cmds.ls(sl=True, 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 = cmds.ls(sl=True, type='transform') | |
print("cmds.select(%s, r=True)" % (nodes)) | |
#Open New Maya | |
from subprocess import call | |
appPath = "/Applications/Autodesk/maya2014/Maya.app" | |
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 = cmds.ls(sl=True) | |
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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Frame Selected PaintWeight Influences | |
import maya.cmds as cmds | |
curSel = cmds.ls(selection=True) | |
pwSelectedInfluences = maya.mel.eval("$temp=$gArtSkinOrderedInfluenceSelectionList") | |
cmds.select(pwSelectedInfluences, r=True) | |
cmds.viewFit() | |
cmds.select(curSel, r=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FrameSelected; | |
fitPanel -selected; | |
animView -startTime (`playbackOptions -query -minTime` - 1) -endTime (`playbackOptions -query -maxTime` + 1) graphEditor1GraphEd; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: | |
curves.append(attrFull) | |
else: | |
unkeyed.append(attrFull) | |
# 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 = cmds.ls(sl=True)[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'], | |
defaultButton='OK', | |
cancelButton='Cancel', | |
dismissString='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]; | |
crvs.append(crv) | |
shape = cmds.listRelatives(crv, shapes=True) | |
shapes.append(shape) | |
# 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): | |
cmds.delete(crvs[idx]) | |
# 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 = cmds.ls( selection=True ) | |
RRM_fixPinBug(objs) | |
''' | |
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 = cmds.ls( 'RRM*Parent' ) | |
for obj in parents: | |
val = cmds.getAttr(obj + '.pinned') | |
print('%s : %s') % (obj, val) | |
RRM_selectParents() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Timeslider | |
timeControl -edit -pressCommand "undoInfo -stateWithoutFlush off;" -releaseCommand "undoInfo -stateWithoutFlush on;" $gPlayBackSlider | |
// Hotkeys | |
// http://www.ricardoayasta.com/2012/02/stop-undo-ing-scrub-time-slider-in-maya.html | |
// 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