Skip to content

Instantly share code, notes, and snippets.

@timborrelli
Created September 18, 2020 19:15
Show Gist options
  • Save timborrelli/05d8a913f84e30b9112d1ead7ca31417 to your computer and use it in GitHub Desktop.
Save timborrelli/05d8a913f84e30b9112d1ead7ca31417 to your computer and use it in GitHub Desktop.
Script to center current time in time slider to a frame range, with a +/- buffer set by the user.
import maya.cmds as cmds
import maya.mel as mel
def swapToRange(buffer):
print 'swap to range'
#get all dem frames
curRangeStart = cmds.playbackOptions(q=True, min=True)
curRangeEnd = cmds.playbackOptions(q=True, max=True)
fullRangeStart = cmds.playbackOptions(q=True, ast=True)
fullRangeEnd = cmds.playbackOptions(q=True, aet=True)
currentTime = cmds.currentTime(q=True)
#figure out direction (are we expanding the range slider or contracting it)
direction = 0 #contract it as default
if ((curRangeStart == fullRangeStart) and (curRangeEnd == fullRangeEnd)):
direction = 0
else:
direction = 1
if direction == 1:
print 'expand'
cmds.playbackOptions(min=fullRangeStart, max=fullRangeEnd)
if direction == 0:
print 'contract'
frameOffset = (buffer/2)
cmds.playbackOptions(min=(currentTime-frameOffset), max=(currentTime+frameOffset))
swapToRange(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment