houdini command line .. python

   15480   9   2
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
Hi !

Let's say I have a houdini scene with a network that imports some data, processes it and exports it to an other folder.

Would there be a way to kick this process on via Python so that I don't need to open Houdini itself ?

Any input welcome !

Thanks !

m.
User Avatar
Member
8594 posts
Joined: July 2007
Online
either open hython from the shell:
http://www.sidefx.com/docs/houdini13.0/hom/commandline#idm47503603268592 [sidefx.com]

or import hou module in your python session


then use hou.hipFile.load() to open hip file
everything after this point is as if you were in python shell within houdini with your hip file opened
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
hmm.. I played around with this, but can't get it to work.

is there anybody that may give me an example script with Python 2.7 that creates e.g. a hip file with a sphere and saves it on the desktop ?
User Avatar
Member
35 posts
Joined: Oct. 2007
Offline
look here:
http://www.sidefx.com/docs/houdini13.0/hom/commandline#idm47503603268592 [sidefx.com]

soo .. source your houdini_setup_bash or whatever first so you have HFS set .. then run python .. import that script “enableHou” from that documentation page .. and go to town in hou:

def makeSphere():
obj = hou.node(“/obj”)
s = obj.createNode('geo', ‘Sphere01’, run_init_scripts=False)
s.createNode('sphere','sphere');

makeSphere()

good luck

-G

ps. almost forgot the save part:

hou.hipFile.save(“test.hip”)
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
hi ..

well, actually exactly the steps ‘before going to town’ are the issue.

how to set things up I had my issues with ..

any example on this would be much appreciated ..

let me know ..

m.
User Avatar
Member
35 posts
Joined: Oct. 2007
Offline
all I've done here is copy the code from the above mentioned documentation page, followed by the code I entered above. Source your houdini_setup_bash (or csh or whatever shell you are using) so that “HFS” gets defined.. and run the code below. This will create a sphere and save a hipfile “test.hip” into the current directory.

-G


#!/usr/bin/python2.7
def enableHouModule():
‘'’Set up the environment so that “import hou” works.'''
import sys, os

# Importing hou will load in Houdini's libraries and initialize Houdini.
# In turn, Houdini will load any HDK extensions written in C++. These
# extensions need to link against Houdini's libraries, so we need to
# make sure that the symbols from Houdini's libraries are visible to
# other libraries that Houdini loads. So, we adjust Python's dlopen
# flags before importing hou.
if hasattr(sys, “setdlopenflags”):
old_dlopen_flags = sys.getdlopenflags()
import DLFCN
sys.setdlopenflags(old_dlopen_flags | DLFCN.RTLD_GLOBAL)

try:
import hou
except ImportError:
# Add $HFS/houdini/python2.6libs to sys.path so Python can find the
# hou module.
sys.path.append(os.environ + “/houdini/python%d.%dlibs” % sys.version_info)
import hou
finally:
if hasattr(sys, “setdlopenflags”):
sys.setdlopenflags(old_dlopen_flags)

def makeSphere():
obj = hou.node(“/obj”)
s = obj.createNode('geo', ‘Sphere01’, run_init_scripts=False)
s.createNode('sphere','sphere');

enableHouModule()
import hou
makeSphere()
hou.hipFile.save(“test.hip”)
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
ranxerox
Source your houdini_setup_bash (or csh or whatever shell you are using) so that “HFS” gets defined..

This is the part that confuses me ..

1] What does ‘HFS’ stand for ?
2] Is ‘houdini_setup_bash’ a script ? a shell ? an exe ?

If I have C:\Python27\python.exe open ( the shell ) and Houdini installed under C:\Program Files\Side Effects Software\Houdini 13.0.198.21, what would be the the steps to do what I quoted of your text ?

I did a lot of scripting before, but this is new territory .. Thanks for the help so far ..

m.
User Avatar
Member
35 posts
Joined: Oct. 2007
Offline
(1) HFS == “Houdini File System” .. it is created by (2) “houdini_setup_bash”, which is a specific script for the bash shell. Bash is the bourne again shell which is popular. Csh is another shell. On windows I'm not sure how it works .. there is probably a link to a specific houdini shell which probably starts dos or whatever with all of the houdini variables set. Or maybe you need to set an environment variable “HFS” which points to “C:\Program Files\Side Effects Software\Houdini 13.0.198.21”. This is getting more into windows specific issues which I'm not the person to answer.

-G

deadalvs
ranxerox
Source your houdini_setup_bash (or csh or whatever shell you are using) so that “HFS” gets defined..

This is the part that confuses me ..

1] What does ‘HFS’ stand for ?
2] Is ‘houdini_setup_bash’ a script ? a shell ? an exe ?

If I have C:\Python27\python.exe open ( the shell ) and Houdini installed under C:\Program Files\Side Effects Software\Houdini 13.0.198.21, what would be the the steps to do what I quoted of your text ?

I did a lot of scripting before, but this is new territory .. Thanks for the help so far ..

m.
User Avatar
Member
678 posts
Joined: July 2005
Offline
deadalvs
ranxerox
Source your houdini_setup_bash (or csh or whatever shell you are using) so that “HFS” gets defined..

This is the part that confuses me ..

1] What does ‘HFS’ stand for ?
2] Is ‘houdini_setup_bash’ a script ? a shell ? an exe ?

http://odforce.net/wiki/doku.php?id=hfs [odforce.net]
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
finally, I tracked down a way to do what I want (win8.1):

Create a .bat file that runs my script
“C:\Program Files\Side Effects Software\Houdini 13.0.401\bin\hython.exe” CUsers/User/Desktop/start.py
pause

in the script:
def makeSphere():
obj = hou.node(“/obj”)
s = obj.createNode('geo', ‘Sphere01’, run_init_scripts=False)
s.createNode('sphere','sphere')


makeSphere()
hou.hipFile.save(“CUsers/User/Desktop/test.hip”)

This creates the .hip file on the desktop.

Thanks for all the inputs !

Matt
  • Quick Links