V-Ray Rendering from RhinoCommon C# Plugin

Hi All,

Currently scratching my head over how to batch render using V-Ray from inside a plugin.

Using the following the renderer starts rendering fine.

Rhino.RhinoApp.RunScript("_-Render", true);

However, I’d like to take further action after the render is done, such as saving the render and loading a new file or turning off a layer and turning another on for the next render etc…

Any ideas on how to do that?

Many thanks

As long as all steps are scriptable, you can send more script commands.
The actions, like loading a new file and turning on/off layers are all scriptable.

To prevent getting a dialog box (“do you want to save changes?”) when you want to open a new file, you can first save the current document to a dummy file. After a document has been saved, you can open another document without any dialog.

Many commands have different behaviour when you run them in scripted mode (with a dash (-) in front of the command name). The Layer command is good example - use this to script layers on/off.

Thanks but I’m not sure I understand your approach.

Tried adding the following line after the render command but that saved the file straight away without waiting for the render to finish.

Rhino.RhinoApp.RunScript("_-SaveRenderWindowAs \"E:\\test.png\"", true);

Not sure if I’m missing something but that didn’t work.

See below for a much better answer.

Ah, ok. Maybe (I don’t know and I haven’t tested) you can wait for the Idle event, prior to saving the file. So, hopefully what happens in the code below is that while rendering Rhino does not enter the Idle state and when the render is complete the Idle event is fired.


bool finished = false;
Action<object, EventArgs> onIdle = () => finished = true;

try {

    RhinoApp.Idle += onIdle;
    Rhino.RhinoApp.RunScript("_-Render", true);

    while (!finished)

    Rhino.RhinoApp.RunScript("_-SaveRenderWindowAs \"E:\\test.png\"", true);
    RhinoApp.Idle -= onIdle;

Enable Batch render in the VRay options, so your script does not get focus until the render has been finished. You can script these rhino commands, to start the render, save it and close the renderwindow:


After closing the render window, you can control layers etc. Apart from this, a few VRay options are accessable using either VRay plugin object or via the VRayForRhinoNETInterface. Here is a long thread to show how to use them via python, it sould work the same for a C# plugin.


Yes that’s exactly where I’m at, namely the Batch Render option in V-Ray.

@menno your code doesn’t work, I tried it simply to see if I can use it in different circumstances.


@clement thanks for the link, that thread looks full of useful info for my current needs, I hope the updated V-Ray .Net lib works and has some goodies in there, going to check right now.

Thanks guys

@netlander, just avoid using CancelRender() mentioned in that thread and do everything with the batchrender option enabled and it should all work. Good luck :wink:


Hello @menno,
can you explain me briefly how it works this line:

bool finished = false;
Action<object, EventArgs> onIdle = () => finished = true;

because its give me the error:
> Delegate ‘System.Action<object,System.EventArgs>’ does not take 0 arguments

Im trying to do something quite similar as @netlander

thanks in advance
kind regards

I’m sorry, I made a mistake. It should be

bool finished = false;
Action<object, EventArgs> onIdle = (obj, args) => finished = true;

thanks a lot