Jump to content

Run Python script after Houdini starts


kiryha

Recommended Posts

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.

Link to comment
Share on other sites

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,

  • Like 1
Link to comment
Share on other sites

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,

Link to comment
Share on other sites

  • 7 months later...

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!

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...