Python from outside houdini

   7011   5   0
User Avatar
Member
57 posts
Joined: Jan. 2015
Offline
I've searched around, but must be asking this wrong as I haven't been able to find anything. So here is my goal.

have a script run from another program, and setup my Houdini scene.

I have done this a couple of ways in the past.

1st. Lightwave is an ASCII file format, so I just write a text scene file. with all the right settings, Works great. However it doesn't appear .hip files are ASCII from what I have found it looks like they are a mix of binary and ASCII, So this doesn't seem like an option. Which is sad. As this give lots of flexibility and the app doesn't even have to be open to edit, and create things.

2nd. Fusion. The Other Way is talk to the program through Python, externally. So in fusion. in python I launch fusion, and then tell it, what the loader and saver is, what the timing is. and where to save the comp. and then close it. All from the outside. Just driving fusion externally. I believe maya can do that as well. It seems like this would be the way to do it in houdini. However, I can't for the life of me find any documentation on how to do it. I would guess it's because I don't know the right way to search for it.

So how do we communicate with Houdini from outside Houdini through Python?
Thanks
Chris
User Avatar
Member
2537 posts
Joined: June 2008
Offline
One way might be to leverage the startup script hooks [odforce.net]. They get run each time Houdini is launched. So all your external app has to do is to write python code and then launch Houdini.

For example, 456.py gets run after Houdini is up and running and the Untitled.hip is loaded. As far as generating a HIP file, you don't really have to. Inside of 456.py you can simply use python commands to create nodes directly. Or import and execute pre-written python code provided by the launching app.

This code will create a Python node in the /obj network and install code into the python node to be executed upon creation complete.
hou_node = hou.node("/obj")
# Update the parent node.
hou_parent = hou_node
# Code for /obj/pythonscript1
hou_node = hou_parent.createNode("pythonscript", "pythonscript1", run_init_scripts=False, load_contents=True, exact_type_name=True)
hou_node.move(hou.Vector2(2.89402, 1.70585))
hou_node.setSelectableInViewport(True)
hou_node.showOrigin(False)
hou_node.useXray(False)
hou_node.setDisplayFlag(True)
hou_node.setSelected(False)
# Code for /obj/pythonscript1/python parm 
if locals().get("hou_node") is None:
    hou_node = hou.node("/obj/pythonscript1")
hou_parm = hou_node.parm("python")
hou_parm.set("print \"Hello World\"\n")

You can discover what code is needed to create any given node by simply asking the node to give you it's code definition.
print node.asCode(brief=True, recurse=False, save_creation_commands=True, save_spare_parms=True)

Set recurse to True to extract an entire subnet of code generation commands.
Edited by Enivob - Dec. 16, 2016 17:02:53
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
57 posts
Joined: Jan. 2015
Offline
yeah I guess I could make a “sceneFile” that would write down the info for each shot, to a text file, and then in Houdini have a script that would batch all the sceneFiles, Making each hiplc file. I was just hoping I would be able to drive houdini from other apps, like you can in fusion.

Then inverse also may work, because my project management software Generation, you can talk to from the outside. I could have Houdini talk to it, and get the info. and then make a scene off of what is selected inside generation. I guess either way would work. Just not as elegant as the. one click inside Generation, to control Houdini,

thanks for the help!
Chris
User Avatar
Member
2537 posts
Joined: June 2008
Offline
You welcome, I have seen other attempts at this by leveraging socket based communication. So if you already have some kind of port based software you might be able to setup a listener inside of Houdini to process commands. 456.py could initialize the listener.
Edited by Enivob - Dec. 16, 2016 17:19:06
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
What you probably want is rpc:
http://www.sidefx.com/docs/houdini/hom/rpc [sidefx.com]

You can also hook directly to hython (python distribution in $HFS). E.g.: I did build setup for Sublime Text were I link build with hython instead of default system python so I could run functions from hou module directly and build/modify/simulate all scenes directly from Sublime Text.
User Avatar
Member
57 posts
Joined: Jan. 2015
Offline
rpc looks like what I want, I'll read up on it,

Thanks!
Chris
  • Quick Links