Nerox Posted February 4, 2011 Share Posted February 4, 2011 Hi Guy's! I wonder if there is a way to execute a python script when Houdini starts. Applications for this might be for instance: Show a project selection GUI. In this case I would like to run the sys.path.append(path to script folder), since it seems that home/user/houdin.X.Y/scripts isn't recognized as a script dir Hope this makes sense :-) Quote Link to comment Share on other sites More sharing options...
SpencerL Posted February 4, 2011 Share Posted February 4, 2011 Hi Guy's! I wonder if there is a way to execute a python script when Houdini starts. Applications for this might be for instance: Show a project selection GUI. In this case I would like to run the sys.path.append(path to script folder), since it seems that home/user/houdin.X.Y/scripts isn't recognized as a script dir Hope this makes sense :-) In your houdini path ie ../houdini/scripts/ there are two different .cmd files. 123.cmd and 456.cmd. The 123.cmd gets run when you open up a new houdini session and 456.cmd gets run when you open up a new scene in an existing session. Im sure Im missing some other technical details to what these scripts do so someone correct me if Im wrong You can modify these to included your own additional pipeline scripts. The .cmd files are in hscript but you can create a python version by calling it the same name ie 123.py/456.py and save it in the same directory. Have your python version source the .cmd file so that all the defaults get run when the python version gets called. import hou hou.hscript("source 456.cmd") then after that you can add your sys.path.append(path to script folder) Quote Link to comment Share on other sites More sharing options...
Nerox Posted February 4, 2011 Author Share Posted February 4, 2011 In your houdini path ie ../houdini/scripts/ there are two different .cmd files. 123.cmd and 456.cmd. The 123.cmd gets run when you open up a new houdini session and 456.cmd gets run when you open up a new scene in an existing session. Im sure Im missing some other technical details to what these scripts do so someone correct me if Im wrong You can modify these to included your own additional pipeline scripts. The .cmd files are in hscript but you can create a python version by calling it the same name ie 123.py/456.py and save it in the same directory. Have your python version source the .cmd file so that all the defaults get run when the python version gets called. import hou hou.hscript("source 456.cmd") then after that you can add your sys.path.append(path to script folder) Awesome :-) The downside of this is that you have to create (or copy) this file every time you install a new build. I'm trying to make my life as easy as possible, obviously , by placing al the scripts in the home/username/houdinix.y/scripts. But I guess I can't get around this one ('eh?' = one of the souvenirs I got from Toronto ;-) Quote Link to comment Share on other sites More sharing options...
symek Posted February 4, 2011 Share Posted February 4, 2011 it's the same this time too. Any script or config from $HFS/houdini can be placed in $HOME/houdinix.y (or $HSITE/houdinix.y or $JOB/(...)) path... Quote Link to comment Share on other sites More sharing options...
Nerox Posted February 4, 2011 Author Share Posted February 4, 2011 (edited) I also noticed that from 123.py, although sys.path.append(path to script folder) works like a charm, any UI type of commands (like hou.ui.displayMessage('hello')) don't seem to have any effect. I also tried to import an external script/module and launch a function from there but this also doesn't seem to have effect. This leads to the question where should I call my 'open project window' which opens when Houdini launches? Edit: I see! I can also store 123.py in $HOME/houdinix.y, that's nice :-). And now the popup window works as well, though it show up at the splash screen, but at least it show up :-). Edited February 4, 2011 by Nerox Quote Link to comment Share on other sites More sharing options...
thefreeman Posted February 4, 2011 Share Posted February 4, 2011 In this case I would like to run the sys.path.append(path to script folder), since it seems that home/user/houdin.X.Y/scripts isn't recognized as a script dir I assume it is a python script that you want to put in /home/user/houdini.X.Y/scripts that Houdini isn't picking up? Try putting it in /home/user/houdini.X.Y/scripts/python. If that doesn't work, try /home/user/houdini.X.Y/python2.xlibs (if you are using python 2.x). I think since Houdini 11 the preferred location for python scripts is the python2.xlibs directory. Quote Link to comment Share on other sites More sharing options...
Nerox Posted February 4, 2011 Author Share Posted February 4, 2011 I assume it is a python script that you want to put in /home/user/houdini.X.Y/scripts that Houdini isn't picking up? Try putting it in /home/user/houdini.X.Y/scripts/python. If that doesn't work, try /home/user/houdini.X.Y/python2.xlibs (if you are using python 2.x). I think since Houdini 11 the preferred location for python scripts is the python2.xlibs directory. I actually tried that first but that doesn't seem to work. the 123.py file like described above and than saved in /home/user/houdini.X.Y/scripts works perfect Quote Link to comment Share on other sites More sharing options...
Johannes Saam Posted March 13, 2011 Share Posted March 13, 2011 Hey, in that relm i have another question. Is it possible in that very python script to add python code to the hou.session() part of things? Basicaly i want to be a able to store a .py file in a directory that contains certain functions specific to the file and then when this file gets opened to append a function to that. This is based on the idea in the python master class about the "bling server" to have a function inside that hip file that once that file is called in hython can be assumed to be there. For example and init function that checks for assets and a render function that is then called on a farm box... am i confusing?! Thanks jo Quote Link to comment Share on other sites More sharing options...
Nerox Posted March 14, 2011 Author Share Posted March 14, 2011 Hey, in that relm i have another question. Is it possible in that very python script to add python code to the hou.session() part of things? Basicaly i want to be a able to store a .py file in a directory that contains certain functions specific to the file and then when this file gets opened to append a function to that. This is based on the idea in the python master class about the "bling server" to have a function inside that hip file that once that file is called in hython can be assumed to be there. For example and init function that checks for assets and a render function that is then called on a farm box... am i confusing?! Thanks jo You mean like importing a module? Quote Link to comment Share on other sites More sharing options...
Johannes Saam Posted March 14, 2011 Share Posted March 14, 2011 You mean like importing a module? like a custom bit of python.. def awesome(): pint 'wohooo' and have that loaded into hou.session() to be used somwhere else... i think i found the answer there is a hou.session function forgot the name that allows you to add function to the module i post uppon completion of this idea Quote Link to comment Share on other sites More sharing options...
Nerox Posted March 14, 2011 Author Share Posted March 14, 2011 like a custom bit of python.. def awesome(): pint 'wohooo' and have that loaded into hou.session() to be used somwhere else... i think i found the answer there is a hou.session function forgot the name that allows you to add function to the module i post uppon completion of this idea Correct me if I'm wrong, but what about creating your own module like re and os, basically a collection of one or more functions stored in a file which you can load in when ever you like. If your module is called 'myModule' and a typical function is called 'functionX()' then you can place 'import myModule' in the 123.py script and then you can call in houdini: 'myModule.functionX()'. If you would like to import an specific fucntion and don't want to type 'myModule' all the time, you can also say: 'from myModule import functionX. Hope this helps Quote Link to comment Share on other sites More sharing options...
Johannes Saam Posted March 14, 2011 Share Posted March 14, 2011 hey i found the answer its supposedly hou.setSessionModuleSource( source ) but i can not get it to work... will post a new thread about this. Jo Quote Link to comment Share on other sites More sharing options...
borbs727 Posted August 22, 2016 Share Posted August 22, 2016 Is there an updated way for doing this in H15.5? I'm having trouble finding anything related to startup scripts for new versions. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted August 23, 2016 Share Posted August 23, 2016 4 hours ago, borbs727 said: Is there an updated way for doing this in H15.5? I'm having trouble finding anything related to startup scripts for new versions. http://www.sidefx.com/docs/houdini/hom/locations 1 Quote Link to comment Share on other sites More sharing options...
borbs727 Posted August 24, 2016 Share Posted August 24, 2016 (edited) Thanks Alex! I was able to get everything working! I ended up creating a 123.py module and putting it inside a custom scripts location and setting the HOUDINI_SCRIPT_PATH. For example: import os HOUDINI_SCRIPT_PATH = 'custom/path/to/houdini/scripts' + os.pathsep + '&' I put all of my code inside of the 123.py module and only put the execution bits into a function. This function was then executed using hdefereval. Example code below. It searches for a pypanel file at a specified PYPAN_PATH. If it doesn't find it, then it creates the file, installs it, and creates it on startup of Houdini: """ 123.py @ houdini.scripts Some code taken from Paul Winex's hqt: https://github.com/paulwinex/hqt/blob/master/hqt_example.py """ import os import sys import tempfile import hou import hdefereval # Path to python_panels dir (must exist already) PYPAN_PATH = os.path.join( 'path/to/module', 'resource', 'houdini', 'python_panels', 'mb_MMV_pypanel.pypanel' ).replace('\\', '/') def createPanelFile(): xml = '''<?xml version="1.0" encoding="UTF-8"?> <pythonPanelDocument> <!-- This file contains definitions of Python interfaces and the interfaces menu. It should not be hand-edited when it is being used by the application. Note, that two definitions of the same interface or of the interfaces menu are not allowed in a single file. --> <interface name="test" label="test_label" icon="MISC_python" help_url=""> <script><![CDATA[import sys from PySide import QtGui path = "path/to/your/UI/source/" if not path in sys.path: sys.path.append(path) import your_module reload(your_module.MainWindow) def createInterface(): widget = your_module.MainWindow.Build() return widget ]]></script> <help><![CDATA[]]></help> </interface> </pythonPanelDocument> ''' pypanel_file = open(PYPAN_PATH, "w") pypanel_file.writelines(xml) pypanel_file.close() print pypanel_file return pypanel_file.name get_pypanel = os.path.isfile(PYPAN_PATH) if get_pypanel == True: panFile = PYPAN_PATH else: print 'create path' panFile = createPanelFile() hou.pypanel.installFile(panFile) pypan = hou.pypanel.interfacesInFile(panFile)[0] def installedInterfaces(): res = [] menu = hou.pypanel.menuInterfaces() for i in menu: try: hou.pypanel.setMenuInterfaces((i,)) res.append(i) except: pass return res menu = installedInterfaces() menu.append(pypan.name()) menu = [x for x in menu if not x == '__separator__'] new = [] for m in menu: if not m in new: new.append(m) def make_panel(): hou.pypanel.setMenuInterfaces(tuple(new)) pane = max(0,len(hou.ui.curDesktop().panes())-1) python_panel = hou.ui.curDesktop().panes()[pane].createTab(hou.paneTabType.PythonPanel) python_panel.setIsCurrentTab() python_panel.showToolbar(0) python_panel.setActiveInterface(pypan) hdefereval.executeDeferred(lambda: make_panel()) The hdefereval was only necessary because I wanted to make changes to Houdini's UI (like create a custom panel). Check out Paul Winex's MSE and hqt to learn more about automating UI creation in Houdini. Edited August 24, 2016 by borbs727 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.