Skip to content

Instantly share code, notes, and snippets.

@yamahigashi
Created July 19, 2013 08:35
Show Gist options
  • Save yamahigashi/6037643 to your computer and use it in GitHub Desktop.
Save yamahigashi/6037643 to your computer and use it in GitHub Desktop.
#softimage PlayControl.Key manipulation plugin
#---------------------------------------------------------------------#
#---------------------------------------------------------------------#
#---------------------------------------------------------------------#
import time
import win32api as win
from win32com.client import constants as c
#---------------------------------------------------------------------#
#------For Instantination---------------------------------------------#
#---------------------------------------------------------------------#
xsi = Application
FASTPLAYBACK_CACHESIZE = 9000 # kb/frame
KEYREPEAT_MARGIN = 0.5
GIZMO_RATE = 3
pc = lambda: xsi.Dictionary.GetObject("PlayControl")
greenkey = lambda: pc().Parameters("Key")
#---------------------------------------------------------------------#
#---------- Register XSI PluginManager--------------------------------#
#---------------------------------------------------------------------#
def XSILoadPlugin(in_reg):
in_reg.Author = "anamorphobia"
in_reg.Name = "green timeline"
in_reg.Email = "[email protected]"
in_reg.URL = ""
in_reg.Major = 0
in_reg.Minor = 1
in_reg.RegisterCommand("gsx_next_greenkey")
in_reg.RegisterCommand("gsx_prev_greenkey")
return True
def XSIUnloadPlugin(in_reg):
strPluginName = in_reg.Name
Application.LogMessage(str(strPluginName) + str(" has been unloaded."))
return True
###############################################################################
def gsx_next_greenkey_Init(ctxt):
cmd = ctxt.Source
#cmd.SetFlag(c.siNoLogging, True)
def gsx_prev_greenkey_Init(ctxt):
cmd = ctxt.Source
#cmd.SetFlag(c.siNoLogging, True)
#cmd.SetFlag(c.siAllowNotifications, False)
def gsx_next_greenkey_Execute():
xsi.SetValue("preferences.scripting.cmdlog", False, "")
NextFrame()
ks = win.GetKeyboardState()
pushed_code = [i for i in range(0x20, 0x8F) if ord(ks[i]) > 1]
press_start = time.time()
while win.GetAsyncKeyState(pushed_code[0]) \
and time.time() < press_start + KEYREPEAT_MARGIN:
pass
prev_time = time.time()
while win.GetAsyncKeyState(pushed_code[0]):
current_time = time.time()
if current_time - prev_time < 0.01666:
time.sleep(0.4)
xsi.Refresh()
xsi.Desktop.RedrawUI()
#win.SetForegroundWindow(xsi)
xsi.Refresh()
NextFrame()
prev_time = current_time
xsi.Refresh()
xsi.SetValue("preferences.scripting.cmdlog", True, "")
def gsx_prev_greenkey_Execute():
xsi.SetValue("preferences.scripting.cmdlog", False, "")
PrevFrame()
ks = win.GetKeyboardState()
pushed_code = [i for i in range(0x20, 0x8F) if ord(ks[i]) > 1]
press_start = time.time()
while win.GetAsyncKeyState(pushed_code[0]) \
and time.time() < press_start + KEYREPEAT_MARGIN:
pass
prev_time = time.time()
while win.GetAsyncKeyState(pushed_code[0]):
current_time = time.time()
if current_time - prev_time < 0.01666:
time.sleep(0.4)
xsi.Refresh()
PrevFrame()
prev_time = current_time
xsi.Refresh()
xsi.SetValue("preferences.scripting.cmdlog", True, "")
def PrevFrame():
greenkey().Value = greenkey().Value - 1
def NextFrame():
greenkey().Value = greenkey().Value + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment