Last active
August 29, 2015 13:59
-
-
Save DomNomNom/10444008 to your computer and use it in GitHub Desktop.
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
from datetime import datetime, timedelta | |
import os | |
import traceback | |
# This code is called when instances of this SOP cook. | |
node = hou.pwd() | |
geo = node.geometry() | |
myLocals = { | |
'hou' : hou, | |
'node' : node, | |
'geo' : geo, | |
} | |
myLocals.update({ | |
p.name() : p.eval() | |
for p in node.parms() | |
if p.name() is not 'pythonFile' | |
}) | |
now = datetime.now() | |
pythonFile = node.evalParm('pythonFile') | |
def readFile(): | |
global lastFileTime, script | |
try: | |
with open(pythonFile) as f: | |
script = f.read() | |
except IOError as e: | |
print 'could not find script file: ', e | |
raise e | |
#print now, 'file refreshed: ', pythonFile | |
lastFileTime = now | |
if 'lastFileTime' not in globals(): | |
readFile() | |
if (now - lastFileTime) > timedelta(seconds=2): | |
readFile() | |
try: | |
globals().update(myLocals) | |
exec(script) | |
except Exception as e: | |
# print 'ERROR: ', e | |
print traceback.format_exc() | |
raise e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
create operator node with a parameter "pythonFile" which is a file selector