Detecting session type

   1062   4   1
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
Hi there;

I'd like to craft a python script in TOPS that does one thing if I'm in an interactive Houdini session (which is to say: working in the UI), and a different thing if the file is being controlled via Hython on the command line (so, no UI). Is this possible, and if so, what is the Python syntax for detecting this?

Thanks!
User Avatar
Member
8539 posts
Joined: 7月 2007
Online
Try this function
https://www.sidefx.com/docs/houdini/hom/hou/isUIAvailable.html [www.sidefx.com]
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
Ah there it is, thanks!
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
Hm, this command seems to actually perform in an unexpected way in TOPS. If I have my scene file open (because I am actively developing in it), but I also open a command prompt session to try testing my setup via hython, I seem to enter some sort of Heisenberg Uncertainty state, where Houdini sees the UI as both open and not open, and I end up getting two scene files saved to two different locations using this Python code in a Python TOP:

import hou
print ("Saving scene...")

# If we are in an interactive session, just save over the current file.
if hou.isUIAvailable():
hou.hipFile.save()

else:
hip_out = hou.contextOption("hip_file_archive")
hou.hipFile.save(hip_out)

This seems to be agitated by a ROP Geometry Output node; upstream of this node, I do not get this weird file duplication problem, but downstream of the node, I do. I can't find any options on the ROP Geometry Output node itself that indicate why it might be, um, forking itself or whatever mysterious behavior it's doing.

I can close my Houdini UI session and things work as expected, but having to constantly open and close Houdini to be able to test my setup is a hassle.
User Avatar
スタッフ
465 posts
Joined: 8月 2019
Offline
You could try using sys.executable to determine if it's running in Houdini or hython.

import sys, os
print(os.path.basename(sys.executable))
  • Quick Links