SaveRenderWindowAs question

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.

c.

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

@juancarreras, in this file:

C:\ProgramData\ASGVIS\VfR564\VRayForRhinoExports.h

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:

C:\ProgramData\ASGVIS\VfR564\VRayForRhinoNETInterface.dll

I see no obvious way do to solve this, even tried to _CopyRenderWindowToClipboard and save this, but it fails as well with an error.

Maybe @matt_newberg knows how to solve this ?

c.

oh well … cannot have everything I guess … :frowning:
Thanks anyway.

@clement

You are correct it was omitted:

Here is a new DLL, and sample script:
VRayForRhinoNETInterface.zip (39.7 KB)

import clr
import System
from Rhino import *
from Rhino.DocObjects import *
from Rhino.Commands import *
from Rhino.Input import *
from Rhino.Input.Custom import *
from scriptcontext import doc
import rhinoscriptsyntax as rs
import Rhino
import array

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)
    Rhino.RhinoApp.WriteLine("Writing:" + file)
    
def RunCommand():
    SaveVFB()
    
RunCommand()

(edited 3/14/2016 - Fixed code sample, incorrectly pasted)

1 Like

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 ?

@juancarreras, in the script posted above, try to add these two missing imports:

import clr
import System  

and change this line to use file instead of path, guess this is a typo

VRayForRhinoNETInterface.VRayInterface.SaveVFBRenderToPath(file, 1)

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:

VRayForRhinoNETInterface.VRayInterface.SaveVFBRenderToPath(file, 1)

or for a example this:

VRayForRhinoNETInterface.VRayInterface.SetDepthOfFieldOn(1)

i get the error message: ‘module’ object has no attribute 'VRayInterface

What really bothers me is that this really works and enables DOF in the options window:

vray.SetDepthOfFieldOn(1)

but accessing vray.SaveVFBRenderToPath(file, 1) gives me the the error message:

_’_ComObject’ object has no attribute ‘SaveVFBRenderToPath’

what could this be ?

c.

Hi @matt_newberg and @clement

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)

VRayForRhinoNETInterface.VRayInterface.SaveVFBRenderToPath(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.

(path, 1) of (path,0). For what I read in

C:\ProgramData\ASGVIS\VfR564\VRayForRhinoExports.h

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()

Is “SaveRenderWindowAs” still being called? If you run said command all channels will be saved.

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)

VRayForRhinoNETInterface.VRayInterface.SaveVFBRenderToPath(file, 1)

Thank you for finding this error. I will go ahead and edit it in the above post.

Sounds like there is an issue with the code sample you are tying to run, can you paste the selection you are using.

Thanks Matt, so what command am I supposed to use to save only the RGB channel ? That was the point …

SaveVFBRenderToPath should save the file/file(s), no other call is needed.

Duh … ! of course. No wonder I was getting three files. That’s great.
Thanks again @matt_newberg

@matt_newberg, below is a simple code snipped which gives me the error and worked before:

ModuleError.py (473 Bytes)

I get identical error if i run one of the example scripts like testApplyObjects.py or animationRender.py.

c.

Sorry, me again …
I’ve implemented the functions within my code and somehow it doesn’t save the file. Not sure what is wrong :slight_smile:

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.

What is the file name you are saving to?

Sorry. Matt I’m not at home. The filename is the saved view name
juan

Sent from my BlackBerry Z30

EDIT: Home now. I’ve cleaned up the message. It really gets messy when sent via email from my phone … sorry

Is it a full path? That function is not very robust, and will need a full path to someplace you can write such as the users desktop.