Hi , how to auto create folder just like maya??

   12453   9   6
User Avatar
Member
46 posts
Joined: Jan. 2012
Offline
Hi , how to auto create folder just like maya??
the render or cache file, always need give the right path.
how cloud I let houdini auto detect if path folder exist,
if not exist then will create one folder?
thank you advance!! :wink:
User Avatar
Member
1621 posts
Joined: March 2009
Online
This has been a theological dispute for quite some time.

Right now the “the pipeline should do it, not Houdini”-disciples are in favor of the gods and so.. you can't do it.

*What you can do of course is create a script that creates folders and ROPs accordingly, that's what I meant with “pipeline”, but for all I know you can't force the ROP to create it
Martin Winkler
money man at Alarmstart Germany
User Avatar
Member
49 posts
Joined: Jan. 2007
Offline
In ROPs at least, ‘Pre-Render Script’ is your friend. Make a Geometry ROP, set the expression type to python then copy pasta this:


import os
path = os.path.dirname(hou.parm('sopoutput').eval())
if not os.path.exists(path):
os.makedirs(path)


Optionally, you can then click on the gear icon and ‘Save as permanant defaults’ - now everytime you create a Geometry ROP you will get a bit of code that makes sure your ‘sopoutput’ (Output File) generates a valid directory. Of course you can tweak the above script to death but it's functional.

For instance, you could substitute ‘sopoutput’ for ‘soho_diskfile’ if this was a Mantra ROP…
User Avatar
Member
1799 posts
Joined: Oct. 2010
Offline
Another option is to use a shell ROP to run a shell command that creates the folder (mkdir in windows). If the folder already exists, it will just spit out that the folder already exists (you can even wrap that as a digital asset with simply using a folder input).

Although i agree the pipeline should handle it, i also see no harm in adding to ROP type operators perhaps a tag to “create output folder if it does not exist”? then that way the user can choose to either make his/her own pipeline or use a built in “create a folder” convenience. I can understand in some cases, it is good to catch that the incorrect folder was inputted, but in some cases, it may do no harm to create the folder if it is applicable in this situation. It all comes down to accessibility

Alternatively, I would at least recommend a noticeable error when the folder does not exist as it currently it is quite quiet when the folder does not exist and it fails to save the file
-G
User Avatar
Member
46 posts
Joined: Jan. 2012
Offline
Thanks All Advance to help me so quick^^
pinkwerks' script is veryuseful!
I just write a Shell version to detected the folder is exist or not.
here is code:

import os

sel = hou.selectedNodes()
for n in sel:
tempPath = n.evalParm('vm_picture')
print tempPath
oldPath = tempPath.split('/')
print oldPath
oldPath_new = oldPath
print oldPath_new
tempPath =
for i in range(0,len(oldPath_new),1):
tempPath.append(oldPath_new)
print tempPath
newPath = os.sep.join(tempPath)
print newPath
if os.path.exists(newPath) == False:
os.mkdir(newPath)


but !
pinkwerks , thanks a lot .
your script always get amazing work^^
short script and very helpful , thx!
User Avatar
Member
617 posts
Joined: Aug. 2008
Offline
nice trick to auto create a folder.
User Avatar
Member
120 posts
Joined: Jan. 2012
Offline
i cant get it workin

i pase this script into pre-render parameter

import os
path = os.path.dirname(hou.parm('soho_diskfile').eval())
if not os.path.exists(path):
os.makedirs(path)

this is what i put in output path in ROP node:
$HIP/render/$HIPNAME/$HIPNAME.$F4.exr

then i get this error:

User defined plane attribute ‘device:IPlay.s3dleftplane’ ‘string’
User defined plane attribute ‘device:IPlay.s3drightplane’ ‘string’
User defined plane attribute ‘device:IPlay.rendermode’ ‘string’
User defined plane attribute ‘device:IPlay.framerange’ ‘string’
User defined plane attribute ‘device:IPlay.currentframe’ ‘real’
User defined plane attribute ‘device:IPlay.rendersource’ ‘string’
User defined plane attribute ‘device:IPlay.houdiniportnum’ ‘int’
Generating Image: /home/tas/Documents/HoudiniProjects/sub/render/sub17.hipnc/sub17.hipnc.0038.exr (768x431)
Plane: Cf+Af (16-bit float)
SampleFilter: alpha
PixelFilter: gaussian 2 2
VEX Type: vector4
Dither: 0.5
Gamma: 1
Gain: 1
White point: 1
mantra: Could not open imager
Error: Failed to create file “/home/tas/Documents/HoudiniProjects/sub/render/sub17.hipnc/sub17.hipnc.0038.exr : No such file or directory”.

im on H12.5 and ubuntu

any fix for that ?
Michal Tas Maciejewski @ www.vfxtricks.com
User Avatar
Member
7715 posts
Joined: July 2005
Offline
Turn on “Create Intermediate Directories” in the ROP node? I don't think there's any need for workarounds now in H12.5.

EDIT: Except for AOVs
User Avatar
Member
120 posts
Joined: Jan. 2012
Offline
right, didnt noticed it.
so much easier

thx
Michal Tas Maciejewski @ www.vfxtricks.com
User Avatar
Member
7 posts
Joined: Nov. 2008
Offline
You could also just use hsript in the “Pre-Render Script”

I usually use some version of the following. It will build the dir if it does not already exist. The -p option create any necessary parent directories as well.

umkdir -p $HIP/_bgeo/$OS/$HIPNAME:r/
  • Quick Links