running python scripts from otls PythonModule

   3071   3   1
User Avatar
Member
382 posts
Joined: July 2005
Offline
Hi, I have a hython script in my HOUDINI_PATH,
it can be run from the a shell, and i can shell out
to it from my otl. This is obviously a much slower
alternative to execFile(hou.findFile(myscript.py))
which I can be run from a python window or shelf
button.

To my surprise, I just noticed that running this same
line from the PythonModule of an otl ignores the import
statements from the script… (ie. from re import match)
Is there another method I can call that will update the
global namespace so i don't get the following Exception?

global name ‘match’ is not defined
User Avatar
Member
382 posts
Joined: July 2005
Offline
looked to work when i passed execFile the global namespace

execFile(hou.findFile('scripts/python/myScript.py'),globals())
User Avatar
Member
382 posts
Joined: July 2005
Offline
hmm, spoke too soon.. the PythonModule invoking
the call would have to import various modules on
behalf of execFile and pass those globals() to the
script. execFile does not import modules of its own.

Once more, if your PythonModule defines some
module-scoped globals, and you pass those to
the execFile script with globals, the execFile script
can clobber those values.

how can this script be invoked in its own namespace
and import the modules it needs without shelling out?
User Avatar
Member
382 posts
Joined: July 2005
Offline
So I grabbed a reference to the local namespace
within the method invoking execFile using locals()
and passed that as the globals argument to execFile.
Seemed to work without clobbering anything since
that namespace goes out of scope with the function.

Still curious if im overlooking something simple…
ie from an hscript section of an hda you can simply
call a .cmd script available in HOUDINI_SCRIPT_PATH
Is there some hom equivalent im overlooking?
  • Quick Links