I have a script that after doing certain operations issues a render command and saves the image to disk.
The code to do that is:
import rhinoscriptsyntax as rs
... code
... more code
rs.Command("!_Render", echo=False)
rs.Command("-_SaveRenderWindowAs " + filename, echo=False)
I’m rendering with vray. The script works fine but it saves all the active channels selected in my VFB vray options tab as separate files.
I would like to save only the RGB result as if I was saving directly from the VFB with the ‘save image’ toolbar icon not the ‘save all image channels’ button.
Is there a different command other than -_SaveRenderWindowAs to save to disk only the RGB channel without having to disable the selected channels first?
@juancarreras, it should render (and save) the channels which are active under vidOptions > VFB Cannels. If you only need RGB you could turn all others off.
hi clement,
well that’s precisely my point. I’d like to save only the RGB channel but I don’t want to have to turn the channels off because I use them mostly, not for compositing but for checking sample rate optimization and noise caused by lights and/or materials.
There has to be a different command to save only the RGB channel but it might be accessible only by vray internal code
there is indeed a function listed named SaveVFBRenderToPath which allows to save the output of a render from the frame buffer and has an option to only save the RGB channel. But as far as i can see, the function is not exposed yet in the NET interface located here:
Thanks @matt_newberg,
I had to ‘unlock’ the two files first but …for the life of me I cannot figure out how to run the script. Is it supposed to save the contents of the VfR to the sample path ? (Desktop\Test.jpg ?) It doesn’t …
Can you explain ?
then render with all your channels enabled. When the render completed, run the script while the render window is open and check if only the RGB image gets saved to the desktop. Does it work ?
…
@matt_newberg, thanks for updating the dll. Unfortunately i cannot test it or run any of the python example scripts anymore since yesterday (this does not have to do with the updated dll.) I can only get the plugin object using:
vray = Rhino.RhinoApp.GetPlugInObject("V-Ray for Rhino")
and import the VRayForRhinoNetIterface but once i try to access it eg. using this line:
I just saw the posts. I’m sorry to hear that you are having problems. In the meantime I’ve had fiddled around with the code. I already had figured out the globals missing.
It seems to work fine now and it saves the contents of the Vfb but if I have the boolean switch set to 1 (file, 1)
I get the RGB (filename.jpg) and the alpha as filename.alpha.jpg
And if If I set the boolean to 0 (file, 0) I get then ** three** files: RGB as filename.jpg, alpha as filename.alpha.jpg and another alpha filename-alpha.jpg
If I set more channels, the issue persists and set to 1 gives me all channels with normal naming and set to 0, the channels come duplicated with “.” and “-” in the name.
around line 471, if the parameter is true it would save only the RGB channel (exactly what I’m after). But in both cases 1 or 0, it saves all the channels. Give it a try (I created a “Test” folder on the Desktop". Although it sounds like you won’t be able to if you still have trouble … Maybe @matt_newberg can explain the problem.
import Rhino
import array
import clr
import System
import rhinoscriptsyntax as rs
def LoadPlugin(path):
if path == None:
return False
# MRhinoPlugIn will be null if it is a C++ plugin
plugin = Rhino.RhinoApp.GetPlugInObject(path)
#print plugin
return plugin
def SaveVFB():
hPlugIn = LoadPlugin("V-Ray for Rhino")
clr.AddReferenceToFileAndPath("C:\ProgramData\ASGVIS\VfR564\VRayForRhinoNETInterface.dll")
import VRayForRhinoNETInterface
path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
file = System.IO.Path.Combine(path, "Test\\" + str(System.Guid.NewGuid()) + ".jpg")
VRayForRhinoNETInterface.VRayInterface.SaveVFBRenderToPath(file, 1)
print(file)
rs.Command("-_SaveRenderWindowAs " + file, echo=False)
Rhino.RhinoApp.WriteLine("Writing:" + file)
def RunCommand():
SaveVFB()
RunCommand()
Sorry, me again …
I’ve implemented the functions within my code and somehow it doesn’t save the file. Not sure what is wrong
import Rhino
import array
import clr
import System
import rhinoscriptsyntax as rs
def LoadPlugin(path):
if path == None:
return False
# MRhinoPlugIn will be null if it is a C++ plugin
plugin = Rhino.RhinoApp.GetPlugInObject(path)
return plugin
def SaveVFB(file):
hPlugIn = LoadPlugin("V-Ray for Rhino")
clr.AddReferenceToFileAndPath("C:\ProgramData\ASGVIS\VfR564\VRayForRhinoNETInterface.dll")
import VRayForRhinoNETInterface
print(file)
VRayForRhinoNETInterface.VRayInterface.SaveVFBRenderToPath(file, 1)
print("Saving " + file)
SaveVFB is called from my script where I get the path, filename and extension from the user and it becomes the string 'file’
The script runs fine and the file complete path-filenme-extension is composed correctly (It prints correctly in "print(file), third line from the end)
However it doesn’t save it. The script basically is a batch render routine to render a series of views associated previously with the sun direction and environment rotation in a dome light. I could post it but it’s quite long.
What it’s relevant is saving as RGB at the end of each rendering.