Jump to content

Run Python script after Houdini starts

Recommended Posts

I am launching Houdini with subprocess:

HOUDINI = 'C:/Houdini 18.0.287/bin/houdinifx.exe'

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.

Share this post

Link to post
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"])



  • Like 1

Share this post

Link to post
Share on other sites
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...

Share this post

Link to post
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

def __init__():
def myFunction():
	#Do your stuff
def myOtherFunction():
	#Do some other stuff


This is my file called by Houdini during the opening process

import myModule





Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now