OPMenu + Python/HOM scripts

   6363   3   1
User Avatar
Member
382 posts
Joined: July 2005
Offline
Is there no OPMenu support for python scripts as
of houdini10.0.345 or am i doing something wrong?

/shots/spi/home/dev/sdugaro]> cat OPmenu
“*/*” vuas “Version Up And Save” ./scripts/python/fx_VerUpAndSave.py
“*/*” fvuas “FULL Version Up And Save” /shots/spi/home/dev/sdugaro/houdini/scripts/python/fx_VerUpAndSave.py

/shots/spi/home/dev/sdugaro/houdini]> pp scripts/python
fx_VerUpAndSave.py@ fx_VerUpAndSave.pyc

/shots/spi/home/dev/sdugaro/houdin]> pp scripts/python/fx_VerUpAndSave.py
/net/vol275/shots/spi/home/dev/sdugaro/houdini/scripts/python/fx_VerUpAndSave.py


Just tried adding
User Avatar
Member
382 posts
Joined: July 2005
Offline
I know i can create a .cmd that invokes a python
script but this is a houdini python script that imports
hou. Seems like it should be supported. Is there
an OPmenu.xml or something?
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
Yeah there's no real good way to embed Python into the opmenu. What I do is have my opmenu entry call some .hsc file and in that .hsc file I have a python -c statement that does something.

OPmenu

'Expr: execute(“otgetotl -b $opmenu_optype”)' debugOTL “Debug OTL” debug.hsc

debug.hsc:

set node = $arg1

python -c “import opmenu_wrapper; reload(opmenu_wrapper); opmenu_wrapper.debug('$node');”


Where the opmenu_wrapper module just has functions that usually call other modules and stuff.

Hopefully one day there will be a nice and awesome OPmenu.xml that makes it all super easy.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
382 posts
Joined: July 2005
Offline
I Took a closer look at this, as it was promising and more or less works, but I ran into a few issues that lead to a solution which I felt merited an ammendment here since documentation is limited on this in general.

Typically one might launch a pyqt app from a main menu with
<scriptPath>python/myapp.py</scriptPath>
or from a shelf button with
execfile(hou.findFile(“scripts/python/myapp.py”))
Where myapp.py might have toplevel launch code in it like

import PyQtHoudini
app = QApplication()
win = MainWindow()
PyQtHoudini.exec(app,win)


The trouble with launching python from a .cmd (hscript) via OPmenu with
python -c “import myapp;reload(myapp);myapp.launch('${arg1}');”
is that when you launch houdini, the module hasnt been imported so when you invoke it for the first time via OPmenu you get two instances of your gui…. One from the first import, and another from the reload. After the module has been imported for the first time, the reload will trigger single launches which is what you want.

If you move the launcher code into a def so that an import doesnt do anything at module level when imported… other than provide bare essential imports and definitions such as


from PyQt4.QtGui import QApplication
from MyApp.MainWindow import MainWindow
def launch(arg=None):
import PyQtHoudini
app = QApplication()
win = MainWindow()
PyQtHoudini.exec(app,win)


Then invoking the following via OPmenu will only import and launch once.
python -c “import myapp;myapp.launch('${arg1}');”

However, doing this doesn't play nice with the above shelf and main menu launch semantics, and will not launch anything… Changing those to the following will allow for your pyqt dialog launcher to invoke once from anywhere:

Shelf Button (can't pass a node, but can pass kwargs)
import myapp
myapp.launch(kwargs)


Main Menu (Nothing to pass from here afict)
<scriptCode><![CDATA[import myapp
myapp.launch(“Main Menu”)]]></scriptCode>


Your launcher or MainWindow code (wherever hou is imported) should be
smart enough to detect the difference in the arguments it receives in order to dispatch or behave accordingly.

Hope this makes life easier for someone. cheers.
  • Quick Links