Python "toolutils.testTool" issue

   2026   3   1
User Avatar
Member
66 posts
Joined: Feb. 2017
Offline
Getting some odd results using the toolutils.testTool to execute a shelf tool via Python in Houdini and I'm hoping someone might be able to let me know if it's potentially a bug that needs a RFE submitted or if it's user error.

The tool in question fires an external .py via execfile. Here is the script of the tool-

execfile(hou.getenv("HOUDINI_CLOUD_PREF_DIR") + '/python2.7libs/testExec.py')

“HOUDINI_CLOUD_PREF_DIR” is a custom environment variable I work with to move preferences off the local machine and onto a network.

Inside of the testExec.py resides the below Python (example simplified)-

from module.newModule import ClassModule as CM

def tester():
    CM().testFire()
tester()

Now, when I click on the shelf tool directly, everything in this script works as expected. module.newModule picks up, ClassModule is imported in fine as CM. CM().testFire() fires an internal function of ClassModule that does a simple print statement for testing.

When executing the tool via “toolutils.testTool()” however, it's a completely different story and an error-
"NameError: global name 'CM' is not defined"

with the following traceback to toolutils-

  File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.431/houdini/python2.7libs\toolutils.py", line 1975, in testTool
    exec(tool.script(), globals(), locals())
  File "<string>", line 1, in <module>

Would anyone be able to please give me a hand sorting out of I'm doing something weird or if a RFE bug report needs to be submitted? I'd expect toolutils.testTool() to yield the same results as manually clicking on the shelf tool.

Thank you,
Clayton
User Avatar
Member
7754 posts
Joined: Sept. 2011
Online
Why not add ‘$HOUDINI_CLOUD_PREF_DIR’ to your houdini path? Then you wouldn't need to use execfile, and you could store shelf tools and otls there too.

As to your problem, I don't know why testTool() would produce different results, but I suspect it runs slightly different context than clicking a tool.
User Avatar
Member
66 posts
Joined: Feb. 2017
Offline
jsmack
Why not add ‘$HOUDINI_CLOUD_PREF_DIR’ to your houdini path? Then you wouldn't need to use execfile, and you could store shelf tools and otls there too.

As to your problem, I don't know why testTool() would produce different results, but I suspect it runs slightly different context than clicking a tool.

‘$HOUDINI_CLOUD_PREF_DIR' is appended into the Houdini Path. I only use execfile for my Python dev .PY file. Like a sandbox.

If testTool's purpose is to execute a shelf tool via python, then the results should not deviate from hte user manually clicking on the shelf button. I figure this is a bug, but wanted to check the forums before submitting a report.

Thank you for the reply.
User Avatar
Member
66 posts
Joined: Feb. 2017
Offline
Alright, letting this sit with the community for a while, I'm going to open up a RFE/bug report on this.

edit:

Instead of using execfile() to fire off a .py I use as a dev/sandbox I am not actually importing it and locals and globals seem to be handled correctly-

here is what I'm not using in my shelf tool to comply better with toolUtils. Bit long winded, but works all the same. No bug submission as long as there is a work-around that probably is less hacky anyways.

import os
import sys

path = os.path.join(hou.getenv('HOUDINI_CLOUD_PREF_DIR'), 'python2/utils')

if not path in sys.path:
    sys.path.insert(0, path)

import hExec
reload(hExec)
Edited by 9krausec - Jan. 4, 2019 14:09:52
  • Quick Links