Jump to content

Post Render Script - python bhclassic to vrmesh


LaidlawFX

Recommended Posts

Trying to make a post-render script on a bgeo rop that when I write a .bhclassic it will rename it to .bgeo, and then I can have vray convert the h11 .bgeo into a vrmesh.

The post rename should be easy, but yeah... I stink at python, or the doing python in the post-render script has some weird syntax. I have switched the drop down to python. I am on windows, so not sure if that is throwing me off.


import glob
import os

for filename in glob.iglob(os.path.join(hou.expandString('`chs("../HscriptDirectoryPath")`'), '*.bhclassic')):
os.rename(filename, filename[:-9] + '.bgeo')[/CODE]

I would like to figure the vrmesh conversion on my own, but if some one know that easily, I would be happy to push off my python learning for the short term once more.

Thanks for the help.

....

One sec may not be a complete python noob, with the first part, of course it worked in the simple test scene I was about to post... guessing it a stupid slash thing

Edited by LaidlawFX
Link to comment
Share on other sites

Guest mantragora

to fix slashes use


import os

filesPath = os.path.join(hou.expandString('`chs("../HscriptDirectoryPath")`'), '*.bhclassic')
fixedPath = os.path.normpath(filesPath)[/CODE]

Edited by mantragora
Link to comment
Share on other sites

Guest mantragora

You mean this vrmesh? I do hope you don't need it for today?

EDIT:

Beside, instead of this

filename[:-9] + '.bgeo'

use

"{0}.{1}".format(filename.split('.')[0], "bgeo")

to change extension in filename

Edited by mantragora
Link to comment
Share on other sites

So this is what I got with some help here... it seems to work... need to clear out the old files now and hope it works at render time


import glob
import os
import subprocess
converterPath = r"C:\Path\To\ply2vrmesh.exe"
for filename in glob.iglob(os.path.join(hou.expandString('`chs("dir")`'), '*.bhclassic')):
filename = os.path.normpath(filename)
#print filename
newfilename = filename[:-10] + '.bgeo'
#print newfilename
os.rename(filename, newfilename)
p = subprocess.Popen([converterPath, "-smoothNormals", "-flipYPosZ", newfilename])
p.wait()
[/CODE]

Link to comment
Share on other sites

Guest mantragora

Works?

Remember that if you want to run a file from Post-Render Script field on Mantra, you need to use

execfile(yourScriptPath)

This field expects code not a path so putting just a path to file will return error. Remember to expandString if the path is from variable

Link to comment
Share on other sites

Ah ok, that explains why we ran into the error with the converterPath being inside

It creates the vrmeshes, but apparently you can not have multiple wait() commands to then remove the temporary .bgeo file. which would be the next step. :\


p = subprocess.Popen([converterPath, "-smoothNormals", "-flipYPosZ", newfilename])
p.wait()
w = os.remove(filename)
w.wait()
[/CODE]

Link to comment
Share on other sites

I'm soo glad there are people smarter than me.... lol.... copy and paste the for loop to just do the remove, lol, soo simple


import glob
import os
import subprocess
converterPath = r[color=#008800][size=2][background=rgb(248, 248, 248)]"C:\Path\To\ply2vrmesh.exe"[/background][/size][/color]

for filename in glob.iglob(os.path.join(hou.expandString('`chs("dir")`'), '*.bhclassic')):
filename = os.path.normpath(filename)
# print filename
newfilename = filename[:-10] + '.bgeo'
# print newfilename
os.rename(filename, newfilename)
p = subprocess.Popen([converterPath, "-smoothNormals", "-flipYPosZ", newfilename])
p.wait()

for filename in glob.iglob(os.path.join(hou.expandString('`chs("dir")`'), '*.bgeo')):
os.remove(filename)[/CODE]

Thanks again mantragora

Edited by LaidlawFX
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...