Last active
June 10, 2018 09:39
-
-
Save paulwinex/db051ab5105c5af5401aa5ef8739ada9 to your computer and use it in GitHub Desktop.
This file contains 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 time, hou | |
# version 1. Static class | |
class SessionCallback(object): | |
last_time = time.time() | |
interval = 10 # sec | |
@classmethod | |
def start(cls): | |
print 'Callback created' | |
# This callback is called approximately every 50ms, unless Houdini is busy processing events. | |
hou.ui.addEventLoopCallback(cls.check_timer) | |
@classmethod | |
def stop(cls): | |
print 'Callback deleted' | |
hou.ui.removeEventLoopCallback(cls.check_timer) | |
@classmethod | |
def check_timer(cls): | |
if time.time() - cls.last_time > cls.interval: | |
cls.last_time = time.time() | |
cls.save() | |
@classmethod | |
def save(cls): | |
print 'SAVE' | |
hou.session.SaveTimer = SessionCallback | |
SessionCallback.start() | |
# SessionCallback.stop() | |
# version 2. Class instance | |
class SessionCallback(object): | |
interval = 10 # sec | |
def __init__(self): | |
self.last_time = time.time() | |
def start(self): | |
print 'Callback created' | |
hou.ui.addEventLoopCallback(self.check_timer) | |
def stop(self): | |
print 'Callback deleted' | |
hou.ui.removeEventLoopCallback(self.check_timer) | |
def check_timer(self): | |
if time.time() - self.last_time > self.interval: | |
self.last_time = time.time() | |
self.save() | |
def save(self): | |
print 'SAVE' | |
hou.session.SaveTimer = SessionCallback() | |
hou.session.SaveTimer.start() | |
# hou.session.SaveTimer.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment