kiryha Posted February 6, 2020 Share Posted February 6, 2020 I am launching Houdini with subprocess: HOUDINI = 'C:/Houdini 18.0.287/bin/houdinifx.exe' subprocess.Popen(HOUDINI) How can I import a Python and run a necessary function after Houdini is launched (import open_asset; open_asset.open())? In Maya I can send MEL command to be executed after Maya starts (and import script with this command): subprocess.Popen('C:/Maya 2019/bin/maya.exe', '-command', "python('execfile(\"path_to_the_script\"')") How can I do something like this in Houdini? The 123.py is not a solution, because I don`t need to run a script each time, only in certain cases, and the scripts are different each time. I need this to open an asset file from Shotgun, for example. Quote Link to comment Share on other sites More sharing options...
DonRomano Posted February 6, 2020 Share Posted February 6, 2020 I know that with the command line tool you can pass this and it executes the script in houdini (at least I tried now with just a print and it prints to the houdini console) : houdini D:\path\to\myfile.hip D:\path\to\mycript.py So maybe you can feed the subprocess with : subprocess.Popen("C:\path\to\houdini.exe", ["D:\path\to\myfile.hip", "D:\path\to\myscript.py"]) Cheers, 1 Quote Link to comment Share on other sites More sharing options...
kiryha Posted February 6, 2020 Author Share Posted February 6, 2020 subprocess.Popen([HOUDINI, ['C:/temp/script.py'], 'argument_one']) That gives me what I need. The only thing I don't know how to run a function from script.py after import... Quote Link to comment Share on other sites More sharing options...
DonRomano Posted February 6, 2020 Share Posted February 6, 2020 I guess you can make 2 python files, one with your functions, and the other one where you source your module and execute the function you need. Like : """ This is my module file where I have defined my functions myModule.py """ def __init__(): pass def myFunction(): #Do your stuff def myOtherFunction(): #Do some other stuff ######################### """ This is my file called by Houdini during the opening process setHoudini.py """ import myModule reload(myModule) myModule.myFunction() myModule.myOtherFunction() Cheers, Quote Link to comment Share on other sites More sharing options...
lukeiamyourfather Posted February 6, 2020 Share Posted February 6, 2020 You could have a script that launches RPC and then do whatever via RPC. Depending on what you're trying to do this might be overkill/cumbersome. https://www.sidefx.com/docs/houdini/hom/rpc.html 1 Quote Link to comment Share on other sites More sharing options...
JesseC Posted September 13, 2020 Share Posted September 13, 2020 I ran into the same problem, and was able to get this to work with the below code: import subprocess houdini_app = ('"C:\\Program Files\\Side Effects Software\\Houdini 18.0.566\\' 'bin\\houdinifx.exe"') houdini_load_file = 'C:\\houdini_filename.hip' houdini_script_path = 'C:\\pythong_filename.py' houdini_cmd = '{} {} {}'.format(houdini_app, houdini_load_file, houdini_script_path) subprocess.Popen( houdini_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True ) Hope this helps someone else! 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.