---
title: "V-Ray Script Access in Grasshopper"
canonical: "https://documentation.chaos.com/space/VRHINO/116131592/V-Ray%20Script%20Access%20in%20Grasshopper"
format: markdown
---
Rendering and exporting proxy meshes, scenes, and animation can be done through Grasshopper's *C# Script* and/or *GHPython Script* components.

The Camera component functions “Get Active Rhino Viewport” and “Look through Camera” can be done through the Script components.

## **Overview**

---

Rendering and exporting proxy meshes and scenes (including animation) can be done through Grasshopper's C# Script and/or GHPython Script components. The methods are listed in the table below.


**Require Render component as input:**

|  |  |
| --- | --- |
| **public bool RenderAnimation();** | Starts animation renderer. |
| **public bool Render(bool sync = false);** | Starts renderer.<br>**true** = function executed synchronously<br>**false** = function executed asynchronously |
| **public string ExportProxy(string filePath, bool animated = false);** | Exports .vrmesh file (**@" .vrmesh"**)<br>**true** = export as animated proxy<br>**false** = export as static proxy |
| **public string ExportScene(string filePath, bool animated = false);** | Exports .vrscene file (**@" .vrscene"**)<br>**true** = export as animated proxy;<br>**false** = export as static proxy |
| **public string ExportSequence(string filePath);** | Exports an animation sequence of V-Ray Scene (.vrscene) files (**@" .vrscene"**) |
| **public bool ExportCloud();** | Submits the current .vrscene file to Chaos Cloud. |



**Require Camera component as input.**

|  |  |
| --- | --- |
| **public void ToView(Rhino.Display.RhinoViewport viewport, bool redraw = true);** | <span style="color: #172b4d">“Look through Camera“ in a specified View</span>  
**true**<span style="color: #172b4d"> = redraw the view </span> |
| **public void FromView(Rhino.Display.RhinoViewport viewport, bool expireSolution = true);** | <span style="color: #172b4d">Sets the Grasshopper Camera in a specified View</span>  
**true**<span style="color: #172b4d"> = solve the component after the parameters were set</span> |
| **public void ToActiveView(bool redraw = true);** | <span style="color: #172b4d">“Look through Camera“ in the Active View</span>  
**true**<span style="color: #172b4d"> = redraw the view</span> |
| **public void FromActiveView(bool expireSolution = true);** | <span style="color: #172b4d">“Get Active Rhino Viewport”</span>  
<span style="color: #172b4d">**true**</span><span style="color: #172b4d"> = solve the component after the parameters were set</span> |


## **C# Script **

---

### **Render Examples**

1. Create a *C# Script* component and plug the renderer output in one of its inputs.

![image](media://99adceea-a70e-4d24-80fe-9e3a9cddf010)


2. Add references to VRaySDK.Net.dll and VRayForGrasshopper.gha

![image](media://472f649f-ee55-44a3-bbbb-785df3861514)


3. In the code editor, cast the input variable to VRayForGrasshopper.Scripting.VRayRenderer.

```c++
VRayForGrasshopper.Scripting.VRayRenderer renderer = x as VRayForGrasshopper.Scripting.VRayRenderer; renderer.Render(false);
```

```csharp
VRayForGrasshopper.Scripting.VRayRenderer renderer = x as VRayForGrasshopper.Scripting.VRayRenderer; renderer.ExportProxy(@"filePath\fileName.vrmesh");
```

```csharp
VRayForGrasshopper.Scripting.VRayRenderer renderer = x as VRayForGrasshopper.Scripting.VRayRenderer; renderer.ExportScene(@"filePath\fileName.vrscene");
```


### **Camera Examples**

---

**Rhino 7**

1. Create a *C# Script* component and plug the Camera output in its **x** input.
2. Right-click on the *C# Script* component > Manage Assemblies and add references to VRaySDK.Net.dll and VRayForGrasshopper.gha.
3. In the code editor, import VRayForGrasshopper (“using VRayForGrasshopper;”) at the beginning of the document.
4. In the code editor, cast the input variable to VRayForGrasshopper.Scripting.VRayCamera.

![C_Sharp_Rhino7_ToView](media://646be34f-d5eb-4a23-b6c9-05a371645c2b)


#### **Examples:**  
  


**ToView - **<span style="color: #172b4d">“Look through Camera“ in a specified View</span>

```c++
Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.Find("Perspective", false);
    VRayForGrasshopper.Scripting.VRayCamera vcam = x as VRayForGrasshopper.Scripting.VRayCamera;
    if(vcam != null)
      vcam.ToView(view.ActiveViewport);
```


**FromView **<span style="color: #172b4d">- Sets the Grasshopper Camera in a specified View</span>

```c++
Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.Find("Perspective", true);
VRayForGrasshopper.Scripting.VRayCamera vcam = x as VRayForGrasshopper.Scripting.VRayCamera;
if(vcam != null)
  vcam.FromView(view.ActiveViewport);
```


**ToActiveView **<span style="color: #172b4d">- “Look through Camera“ in the Active View</span>

```c++
 (x as VRayForGrasshopper.Scripting.VRayCamera).ToActiveView();
```


**FromActiveView**<span style="color: #172b4d"> - “Get Active Rhino Viewport”</span>

```c++
(x as VRayForGrasshopper.Scripting.VRayCamera).FromActiveView();
```


---


**Rhino8**

1. Create a *C# Script* component and plug the Camera output in its **x** input.
2. In the code editor, import VRayForGrasshopper at the beginning of the document:  
// r "VRayForGrasshopper.gha"  
using VRayForGrasshopper;
3. In the code editor, cast the input variable to VRayForGrasshopper.Scripting.VRayCamera.


#### **Examples:**


**ToView - **<span style="color: #172b4d">**“Look through Camera“ in a specified View**</span>

```c++
Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.Find("Perspective", false);
if(x is VRayForGrasshopper.Scripting.VRayCamera vcam)
  vcam.ToView(view.ActiveViewport); 
```



## **GhPython Script **

---

### **Render Examples**

1. Create a GhPython Script component and plug the renderer output in one of its inputs.

![image](media://cf54df91-6268-4db2-b6f0-5cb90a14c296)


2. In the code editor, call any of the above methods on the input variable.

![image](media://a721a1ba-f134-464b-810f-e361b19aa6ea)


### **Camera Examples**

---


<span style="color: #172b4d">**1. Create a **</span>***GhPython Script / Python 3 Script / IronPython 2 Script***<span style="color: #172b4d">** component and plug the Camera output in its **</span>**x**<span style="color: #172b4d">** input.**</span>  
<span style="color: #172b4d">**2. In the Script editor, import Rhino and write the script**</span>


#### **Examples:**


**ToView - **<span style="color: #172b4d">“Look through Camera“ in a specified View</span>

```c++
import Rhino
view = Rhino.RhinoDoc.ActiveDoc.Views.Find("Perspective", True);
x.ToView(view.ActiveViewport, True);
```


<span style="color: #172b4d">**FromView **</span><span style="color: #172b4d">- Sets the Grasshopper Camera in a specified View</span>

```c++
import Rhino
view = Rhino.RhinoDoc.ActiveDoc.Views.Find("Perspective", True);
x.FromView(view.ActiveViewport, True);
```


<span style="color: #172b4d">**ToActiveView **</span><span style="color: #172b4d">- “Look through Camera“ in the Active View</span>

```c++
x.ActiveView()
```


**FromActiveView **<span style="color: #172b4d">- “Get Active Rhino Viewport”</span>

```c++
x.FromView()
```