Skip to content

Instantly share code, notes, and snippets.

@DomNomNom
Last active August 29, 2015 13:59
Show Gist options
  • Save DomNomNom/10444008 to your computer and use it in GitHub Desktop.
Save DomNomNom/10444008 to your computer and use it in GitHub Desktop.
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
@DomNomNom
Copy link
Author

create operator node with a parameter "pythonFile" which is a file selector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment