I have a 123.py file that imports another module. In that module, I have some code that is suppose to set the viewport to look out a specific camera. The code looks something like this:
import toolutils defCam = hou.node(“/obj/defCam”) scene_view = toolutils.sceneViewer() viewport = scene_view.curViewport() viewport.setCamera(defCam) * assume defCam has been already been setup
If I run this snippet from Python shell inside Houdini there is no issue. However, when it runs during initial launch of Houdini (double click on desktop icon), I get the following error:
Error running Python code: Traceback (most recent call last): File “C:<hidden_path>/Documents/houdini16.0/scripts/123.py”, line 20, in <module> import startup File “<hidden_path>/houdini/scripts/python\startup.py”, line 27, in <module> scene_view = toolutils.sceneViewer() File “CPROGRA~1/SIDEEF~1/HOUDIN~1.736/houdini/python2.7libs\toolutils.py”, line 73, in sceneViewer primarypane = hou.ui.paneTabOfType(hou.paneTabType.SceneViewer, index) File “CPROGRA~1/SIDEEF~1/HOUDIN~1.736/houdini/python2.7libs\hou.py”, line 46554, in paneTabOfType return _hou.ui_paneTabOfType(*args) NotAvailable: Not available in this context. No desktops are available
Any idea why it runs fine when inside Houdini but fails during startup? Is there a better way to achieve this? TIA
Cheers, Rob Digital Supervisor | Stargate Studios Toronto
The startup script in the pipeline tools at the studio where I work spawns a thread that waits for houdini's ui to be available, then executes code that requires the ui.
Hmm..that actually works? I assume then a thread is spawned inside 123.py and then 123.py exits so Houdini can continue on. Then in the thread I imagine a loop hangs out with a TRY/EXCEPT attempting to access a portion of the UI interface. When the TRY works, the loop exits and then the rest of the code can run with a valid context established.
Using Houdini Indie 20.5 Windows 11 64GB Ryzen 16 core. nVidia 3060RTX 12BG RAM.
Moved code into another py file and imported that from 456.py (didn't need to use 123.py after all). Also found I needed to add hou.uitriggerUpdate() call. So the code looks like this: