Python Shelf Tool executable location

   4393   10   1
User Avatar
Member
14 posts
Joined: May 2017
Offline
Hey all, I'm making a shelf tool that loads an external .ui file using the QUiLoader class from PySide2. My issue at the moment is determining where I need to place this .ui file so I can reference it relatively when loading it within the script.

Does anyone know what directory location shelf tools are executed from?

Thanks!
User Avatar
Member
2625 posts
Joined: June 2008
Offline
Check out the docs…
http://www.sidefx.com/docs/houdini/hom/locations.html [www.sidefx.com]

http://www.sidefx.com/docs/houdini/hom/tool_script.html [www.sidefx.com]
Edited by Enivob - Nov. 21, 2017 15:20:09
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
14 posts
Joined: May 2017
Offline
Enivob
Check out the docs…
http://www.sidefx.com/docs/houdini/hom/locations.html [www.sidefx.com]

http://www.sidefx.com/docs/houdini/hom/tool_script.html [www.sidefx.com]

I've read both of these sources, so either I'm not quite seeing where it explains this, or the documentation doesn't elaborate on where shelf tools execute from on the file system.
User Avatar
Member
2625 posts
Joined: June 2008
Offline
You could look into executing an Hscript command inside of python to fetch one of the convenient global variables, like $HOME.
https://www.sidefx.com/docs/houdini/hom/hou/hscript.html [www.sidefx.com]
http://www.sidefx.com/docs/houdini/hom/hou/hscriptExpression.html [www.sidefx.com]
Edited by Enivob - Nov. 21, 2017 18:04:53
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
45 posts
Joined: Feb. 2014
Offline
import os
os.environ['HOME']

That will give you the path to the Houdini User folder.
User Avatar
Member
14 posts
Joined: May 2017
Offline
Enivob
You could look into executing an Hscript command inside of python to fetch one of the convenient global variables, like $HOME.
https://www.sidefx.com/docs/houdini/hom/hou/hscript.html [www.sidefx.com]
http://www.sidefx.com/docs/houdini/hom/hou/hscriptExpression.html [www.sidefx.com]

Looks like it defaults to executing from $HOME. This is inconvenient because $HOME could be in a completely different location than where the shelf tool definition is being stored. I am distributing the shelf tool in a collection of files that get added to HOUDINI_PATH. I want to be able to package the .ui file alongside that and have everything work in terms of relative paths. Any solutions for this?
User Avatar
Member
45 posts
Joined: Feb. 2014
Offline
If your folder is in the Houdini path then you can use
hou.findDirectory(dir)
User Avatar
Member
14 posts
Joined: May 2017
Offline
Thomas Bishop
If your folder is in the Houdini path then you can use
hou.findDirectory(dir)

The user may download the toolset to anywhere on their computer. So the .shelf file and the directory it lives in may not be necessarily (and most likely will not be) in the Houdini path.
User Avatar
Member
14 posts
Joined: May 2017
Offline
I figured it out.

dir = os.path.dirname(hou.shelves.runningTool().filePath())

hou.shelves.runningTool() returns the current running hou.Tool, which you can call filePath() on to find where its definition is stored. Use os.path.dirname to find the directory that file is contained in.
User Avatar
Member
1 posts
Joined: Nov. 2013
Offline
I am resurrecting this topic as I don't quite understand.

If I have a file C:\Users\foo\Desktop\python_script_I_want_to_execute_when_I_push_my_shelf_tool.py

What is required to input into my shelf tool script in order to have it execute that file?

Any info would be much appreciated.
User Avatar
Member
14 posts
Joined: May 2017
Offline
Matthew Bennett
I am resurrecting this topic as I don't quite understand.

If I have a file C:\Users\foo\Desktop\python_script_I_want_to_execute_when_I_push_my_shelf_tool.py

What is required to input into my shelf tool script in order to have it execute that file?

Any info would be much appreciated.

Are you seeking to import that module? If so, “C:\Users\foo\Desktop” needs to be in PYTHONPATH (set in houdini.env), and you'd import the module like normal in your shelf script i.e.:
import python_script_I_want_to_execute_when_I_push_my_shelf_tool

Obviously, you'd package a directory with all your scripts alongside your shelf tool.
  • Quick Links