kiryha Posted April 22, 2019 Share Posted April 22, 2019 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... Quote Link to comment Share on other sites More sharing options...
vtrvtr Posted April 22, 2019 Share Posted April 22, 2019 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 1 Quote Link to comment Share on other sites More sharing options...
kiryha Posted April 22, 2019 Author Share Posted April 22, 2019 Thanks, will check them! I did not think about rendering multiple hip files from that perspective, went with first what comes to my mind. Quote Link to comment Share on other sites More sharing options...
vtrvtr Posted April 22, 2019 Share Posted April 22, 2019 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 1 Quote Link to comment Share on other sites More sharing options...
kiryha Posted April 22, 2019 Author Share Posted April 22, 2019 (edited) 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 April 22, 2019 by kiryha Quote Link to comment Share on other sites More sharing options...
vtrvtr Posted April 22, 2019 Share Posted April 22, 2019 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 1 Quote Link to comment Share on other sites More sharing options...
kiryha Posted April 24, 2019 Author Share Posted April 24, 2019 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... Quote Link to comment Share on other sites More sharing options...
kiryha Posted April 25, 2019 Author Share Posted April 25, 2019 (edited) Ok, build a tool to render a list of HIP files without Hscript and batch files, via Python Directly. Edited April 26, 2019 by kiryha Quote Link to comment Share on other sites More sharing options...
Outlawed Posted September 9, 2019 Share Posted September 9, 2019 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. Quote Link to comment Share on other sites More sharing options...
berkninan Posted November 8, 2021 Share Posted November 8, 2021 To call an external command in a Python script, use any of the following methods: subprocess.run() //Python 3.5+ only. You can get the stdout, stderr, the "real" status code, better error handling, etc... os.system() It passes the command and arguments to your system's shell. subprocess.call() function subprocess.Popen Class os.popen() function Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.