Hi all, i wrote a pre render script and i put it in my mantra node.
This script checks whether the destinated folder exists… if it doesn't exist, a folder will be created.
When I click “render”, it doesn't seem to have run my script… cos the folder still isn't created and houdini stops rendering my file.
Here's my code: (simple one)
import hou
import os
curNodeLs = hou.pwd().__str__()
curNode = curNodeLs.split(“/”)
a = hou.node(curNodeLs)
aLs = a.evalParm(“picture”).split(“/”)
checkPath = “”
for i in range(aLs.__len__()-1):
checkPath += (aLs+“/”)
if not os.path.isdir(checkPath):
os.mkdir(checkPath)
please guide… any expert.
I am only 1month old houdini user…
Trying to write a pre-render script... Fail?
16837 13 1- diskhub
- Member
- 32 posts
- Joined: Dec. 2008
- Offline
- rdms
- Member
- 201 posts
- Joined: July 2005
- Offline
- rdg
- Member
- 401 posts
- Joined:
- Offline
- diskhub
- Member
- 32 posts
- Joined: Dec. 2008
- Offline
- rdg
- Member
- 401 posts
- Joined:
- Offline
Shelf Scripts are the tools in the shelf - there not attached to anything afaik.
More information: http://www.sidefx.com/index.php?option=com_content&task=view&id=966&Itemid=265 [sidefx.com]
More information: http://www.sidefx.com/index.php?option=com_content&task=view&id=966&Itemid=265 [sidefx.com]
this is not a science fair.
- Alanw
- Member
- 320 posts
- Joined: Aug. 2007
- Offline
You can place your code in the Python Source window and call it as a function. hou.session.foo() Any code placed there will get saved with your HIP.
You can also create a digital asset with your ROP node inside. Within this asset you can place as much python code as you like in your own module. The docs have good examples for this. http://www.sidefx.com/docs/houdini9.5/hom/assetscripts [sidefx.com]
You can also create a digital asset with your ROP node inside. Within this asset you can place as much python code as you like in your own module. The docs have good examples for this. http://www.sidefx.com/docs/houdini9.5/hom/assetscripts [sidefx.com]
- diskhub
- Member
- 32 posts
- Joined: Dec. 2008
- Offline
i am still not convinced why my pre-render script doesn't work. Can anyone prove to me that pre-render script has certain use?
I understand about the hou.session but i cannot see how i can make it automatic search for an existing directory when i press the “Render” button on the mantra node…
need more help seriously… thanks
I understand about the hou.session but i cannot see how i can make it automatic search for an existing directory when i press the “Render” button on the mantra node…
need more help seriously… thanks
- graham
- Member
- 1908 posts
- Joined: Nov. 2006
- Online
Without seeing exactly how your scene is set up I think what you are trying to do is run your code in an external script file? If you are doing this as by just selecting the script in the file chooser, your script has no concept of a current working directory (hou.pwd()). In order to be able to pass that information to your node, you have to reformat your script so that it works in a function and then import and execute that function in the render script parm like in the following:
myrenderscript.py
import hou
def foo(ropnode):
print ropnode.path()
On the Mantra rop, set it to Python and then in the parameter you can type:
import myrenderscript; myrenderscript.foo(hou.pwd())
This allows you to pass information to your script, rather than it just being run straight up as a script similar to execfile() where it is oblivious to any context it is being run in.
As Alan mentioned, you could also place the code in the hou.session module and call it by setting the parm to:
hou.session.foo(hou.pwd())
myrenderscript.py
import hou
def foo(ropnode):
print ropnode.path()
On the Mantra rop, set it to Python and then in the parameter you can type:
import myrenderscript; myrenderscript.foo(hou.pwd())
This allows you to pass information to your script, rather than it just being run straight up as a script similar to execfile() where it is oblivious to any context it is being run in.
As Alan mentioned, you could also place the code in the hou.session module and call it by setting the parm to:
hou.session.foo(hou.pwd())
Graham Thompson, Technical Artist @ Rockstar Games
- rdg
- Member
- 401 posts
- Joined:
- Offline
insert some print statements and watch the shell for output.
Maybe the paths you generate aren't valid?
Hard to debug from just looking at a script
Though it's not a prove I used successfully pre/post-render scripts to toggle switches and states as a substitute for takes.
And I had bad experience storing scripts in the session module. Especially path related scripts tend to be removed completely from the hip file on loading, once the paths change. I'd go for the ‘HDA route, though it’s more rocky.
Maybe the paths you generate aren't valid?
Hard to debug from just looking at a script
Though it's not a prove I used successfully pre/post-render scripts to toggle switches and states as a substitute for takes.
And I had bad experience storing scripts in the session module. Especially path related scripts tend to be removed completely from the hip file on loading, once the paths change. I'd go for the ‘HDA route, though it’s more rocky.
this is not a science fair.
- diskhub
- Member
- 32 posts
- Joined: Dec. 2008
- Offline
rdg
insert some print statements and watch the shell for output.
Maybe the paths you generate aren't valid?
Hard to debug from just looking at a script
Though it's not a prove I used successfully pre/post-render scripts to toggle switches and states as a substitute for takes.
And I had bad experience storing scripts in the session module. Especially path related scripts tend to be removed completely from the hip file on loading, once the paths change. I'd go for the ‘HDA route, though it’s more rocky.
Hi Graham,
your method sounds logical and i did the following step; but still it didn't work.
1. I placed the following script in a directory where houdini python sys.path is pointed.
mk_folder.py
import hou
import os
def cc_mkDir(ropnode):
curNodeLs = ropnode.__str__() #hou.pwd().__str__()
curNode = curNodeLs.split(“/”)
a = hou.node(curNodeLs)
aLs = a.evalParm(“picture”).split(“/”)
checkPath = “”
for i in range(aLs.__len__()-1):
checkPath += (aLs+“/”)
if not os.path.isdir(checkPath):
os.mkdir(checkPath)
f = open('Dabc.txt, ‘w’)
f.write(curNodeLs)
f.close()
def cc_def():
print “hihi World”
2. I tried using the python shell in houdini to run cc_def() and it works.
3. I tried the last procedure from graham's advice but it does not work
Advise further? Sorry for the trouble…
i really need to know how to run a pre-render script to understand how python can be run in houdini
Desperate…
- graham
- Member
- 1908 posts
- Joined: Nov. 2006
- Online
After copying your code into a mk_folder.py on my machine I was able to cc_def to work fine. The problem is the fact that your code in cc_mkDir fails early on. If you try and run the mkDir function from the shell it outputs your error.
It fails where you go a = hou.node(curNodeLs). This call is both incorrect and if it did work it is redundant because it would be giving you the same thing as “ropnode”. hou.node() takes a full node path, not merely a name like you are doing now. For this to work you would have to make curNodeLs = ropnode.path(). This call to create “a” is failing and thus giving a None type object. When you try and do a.evalParm it raises an exception and the script stops. I was able to correct this and it worked fine.
Here's my take on what you are trying to do. It uses the os.path.split function to isolate the directory path so there is no splitting and iterating necessary.
Hope that helps.
def cc_mkDir(ropnode):
# Evaluate the Picture parameter to get the file we wish
# to render to.
image_path = ropnode.evalParm(“picture”)
# Split the path to get the directory.
dir_path = os.path.split(image_path)
if not os.path.isdir(dir_path):
os.mkdir(dir_path)
# Write the rop name to the file.
f = open(image_path, ‘w’)
f.write(ropnode.name())
f.close()
It fails where you go a = hou.node(curNodeLs). This call is both incorrect and if it did work it is redundant because it would be giving you the same thing as “ropnode”. hou.node() takes a full node path, not merely a name like you are doing now. For this to work you would have to make curNodeLs = ropnode.path(). This call to create “a” is failing and thus giving a None type object. When you try and do a.evalParm it raises an exception and the script stops. I was able to correct this and it worked fine.
Here's my take on what you are trying to do. It uses the os.path.split function to isolate the directory path so there is no splitting and iterating necessary.
Hope that helps.
def cc_mkDir(ropnode):
# Evaluate the Picture parameter to get the file we wish
# to render to.
image_path = ropnode.evalParm(“picture”)
# Split the path to get the directory.
dir_path = os.path.split(image_path)
if not os.path.isdir(dir_path):
os.mkdir(dir_path)
# Write the rop name to the file.
f = open(image_path, ‘w’)
f.write(ropnode.name())
f.close()
Graham Thompson, Technical Artist @ Rockstar Games
- diskhub
- Member
- 32 posts
- Joined: Dec. 2008
- Offline
- graham
- Member
- 1908 posts
- Joined: Nov. 2006
- Online
- diskhub
- Member
- 32 posts
- Joined: Dec. 2008
- Offline
graham
Glad I could help. I also submitted a bug about the lack of error output when running the scripts from Mantra nodes.
yup, that one is very serious… if i knew my script had a problem, it won't be as so complicated… it seriously need an output window to print out error and result just like a shell.
cheers
-
- Quick Links