Jump to content
kiryha

Run script in Command Line tools with Python

Recommended Posts

I have a render.cmd file with a list of hip files to render:

mread P:/PROJECTS/NSI/PROD/3D/scenes/RENDER/000/SHOT_010/RND_E000_S010_001.hiplc
render -f 1 2 -V /out/RENDER
mread P:/PROJECTS/NSI/PROD/3D/scenes/RENDER/000/SHOT_020/RND_E000_S020_001.hiplc
render -f 1 2 -V /out/RENDER


If I open hcmd.exe and run:

hscript render.cmd


I get all my shots rendered. 

The issue is that I can't get it working with Python, currently able only run Command Line Tools 

import subprocess
cmdTools = '"C:/Program Files/Side Effects Software/Houdini 17.0.459/bin/hcmd.exe"'
subprocess.call(cmdTools)


but have no idea how to execute <hscript render.cmd> later...

Share this post


Link to post
Share on other sites

Is there a reason you're not rendering using python directly? You can check inside $HFS/bin/hrender.py or render.py for some examples. If your usage is simple, those scripts would be enough for you to use directly

  • Like 1

Share this post


Link to post
Share on other sites

If you want to render the files sequentially, you can do the same you did in that .cmd, but in python. Something like

hou.hipFile.load(file1)
rop = hou.node(path_to_rop)
rop.render(args)

hou.hipFile.load(file2)
rop = hou.node(path_to_rop)
rop.render(args)

...

If you want to to spawn new processes to render your files, you can call hrender using subprocess

subprocess.Popen([path_to_hython, path_to_hrender, hrender_args]) 

And, of course, you can write a specific custom python script to suit any other needs

 

 

  • Like 1

Share this post


Link to post
Share on other sites

For the first case, I need to import hou module in standalone Python. This is not working:

import sys
sys.path.append('C:/Program Files/Side Effects Software/Houdini 17.0.459/houdini/python2.7libs')
import hou

For the second, can you, please, provide examples of arguments (path_to_hython, path_to_hrender, hrender_args)?

Mine is not working...

import subprocess
cmdTools = '"C:/Program Files/Side Effects Software/Houdini 17.0.459/bin/hcmd.exe"'
batch = 'hscript P:/RENDER/render.cmd'
subprocess.call([cmdTools, batch])

 

Edited by kiryha

Share this post


Link to post
Share on other sites

Sure, here's a hip.

The code is all inside the pythonscript node. It's the following:

import os.path as op
import subprocess

hython_path = op.join(hou.expandString("$HFS"), "bin", "hython")
hrender_path = op.join(hou.expandString("$HFS"), "bin", "hrender.py")
hip_path = hou.hipFile.path()

subprocess.Popen([hython_path, hrender_path, "-e", "-d", "mantra1", hip_path])

As for importing hou, it's not very straight forward. Besides adding the path to the .py file to your current python path, you need to also add the $HFS/bin folder to your PATH variable in order to correctly import the custom houdini C libraries. As described here http://www.sidefx.com/docs/houdini/hom/commandline.html
  

 

subprocess_hython_odf.hip

  • Like 1

Share this post


Link to post
Share on other sites

If I load and render file via Python directly:

hou.hipFile.load(file1)
rop = hou.node(path_to_rop)
rop.render(args)

Does it use the same amount of memory as in the case with hscript? As far as I understand you need to load hip file anyway, but if you load it in Houdini it may take a lot of resources to draw the scene in viewport...
 

Share this post


Link to post
Share on other sites

You can write a .py file to load a hipfile, set render frame ranges etc, and execute the ROP  ( pressButton() command ).

Save that .py file on disk, then just run:

hython /path/to/your/file.py

 

Hython is the non-gui python version of Houdini.  Just like how hbatch is the Hscript non-GUI version of Houdini.

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

×