Skip to content

Instantly share code, notes, and snippets.

@Onefabis
Created March 1, 2018 22:13
Show Gist options
  • Save Onefabis/b6e45c65f232fd126afdf9668e802d5e to your computer and use it in GitHub Desktop.
Save Onefabis/b6e45c65f232fd126afdf9668e802d5e to your computer and use it in GitHub Desktop.
Advanced playback for maya
'''
Just assign to any hotkey short commented code below
import playAdvanced
mods = mc.getModifiers()
if mods == 1:
playAdvanced.playFromTheBeginning()
elif mods == 4:
playAdvanced.loadSteppedScript( 4 )
else:
playAdvanced.playFromTheCurrent()
'''
import maya.cmds as mc
def playFromTheBeginning():
global currentTLFrame
if not mc.play( q=1, state=1 ):
currentTLFrame = mc.currentTime( q=1 )
minRange = mc.playbackOptions( q=1, min=1 )
mc.currentTime( minRange )
mc.play( state=1 )
else:
mc.currentTime( currentTLFrame )
mc.play( state=0 )
def playFromTheCurrent():
global currentTLFrame
print mc.play( q=1, state=1 )
if not mc.play( q=1, state=1 ):
mc.play( state=1 )
currentTLFrame = mc.currentTime( q=1 )
else:
mc.currentTime( currentTLFrame )
mc.play( state=0 )
# Run 'PlayStepped' mode
def playStepped():
print 'stepped'
global oTimeWarp
global oTimeWrapStatus
global obLTemp
global nodeSTName
try:
nodeSTName
except:
nodeSTName = None
obLTemp = mc.ls( sl=1 )
tr = mc.ls( typ='transform' )
if tr or obLTemp:
minP = mc.playbackOptions( q=1, min=1 )
maxP = mc.playbackOptions( q=1, max=1 )
xList=[]
try:
if obLTemp:
xCurves = mc.keyframe( obLTemp, q=1, name=1 )
else:
xCurves = mc.keyframe( tr, q=1, name=1 )
xList = sorted( list( set( mc.keyframe( xCurves, q=1, tc=1, t=( minP,maxP ) ) ) ) )
except TypeError:
pass
if xList:
nodeSTName = 'tempStepCurve'
mc.createNode('animCurveTT', n=nodeSTName)
for x in xList:
flX = float( x )
mc.setKeyframe( nodeSTName, t=(flX,flX), v=flX )
mc.keyTangent( nodeSTName, ott='step', t=(flX,flX) )
oTimeWarp = mc.connectionInfo( 'time1.timewarpIn.timewarpIn_Raw', sourceFromDestination=1 )
oTimeWrapStatus = mc.getAttr('time1.enableTimewarp')
mc.connectAttr( nodeSTName + '.apply', 'time1.timewarpIn.timewarpIn_Raw',f=1)
mc.setAttr('time1.enableTimewarp', 1)
mc.play()
else:
return
def removeStep():
global oTimeWarp
global oTimeWrapStatus
global obLTemp
global nodeSTName
try:
if nodeSTName:
if mc.objExists( nodeSTName ):
mc.delete( nodeSTName )
if (oTimeWarp!=''):
mc.connectAttr( oTimeWarp, 'time1.timewarpIn.timewarpIn_Raw',f=1)
mc.setAttr('time1.enableTimewarp', oTimeWrapStatus)
mc.select( obLTemp, r=1 )
except: pass
def loadSteppedScript( mod ):
global currTime
if mod is None:
mod = mc.getModifiers()
try:
currTime
except:
currTime = None
if not mc.play( q=1, state=1 ):
if mod == 4:
currTime = mc.currentTime( q=1 )
mc.currentTime( mc.playbackOptions( q=1, min=1 ) )
mc.scriptJob( ct=['playingBack',removeStep], runOnce=1 )
playStepped()
else:
if currTime:
mc.currentTime( currTime )
currTime = None
removeStep()
mc.play( state=0 )
if mc.modelEditor( mc.getPanel( wf=1 ), q=1, rnm=1 ) != 'base_OpenGL_Renderer':
mc.ogs( reset=1 )
ctrlsUI = mc.lsUI('MayaWindow',type='control')
for ctrlUI in ctrlsUI:
if ('symbolButton' in ctrlUI):
if (mc.symbolButton(ctrlUI, q=1, c=1)=='playButtonForward'):
mc.symbolButton(ctrlUI, e=1, c='import maya.mel; maya.mel.eval("play -state (!`play -q -state`);")')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment