---
title: "V-Ray for Revit Public API"
canonical: "https://documentation.chaos.com/space/VREVIT/162037839/V-Ray%20for%20Revit%20Public%20API"
format: markdown
---
## **Overview**

---

## **Service Definition (public_api.proto)**

---

> Macro (highlight)
> 
> `public_api.proto`

> Macro (highlight)
> 
> `PublicApi.cs`

> Macro (highlight)
> 
> `PublicApiGrpc.cs`

> Macro (panel)
> 
> service ApiServer {
> 
>   rpc GetProjectName (GetProjectNameRequest) returns (GetProjectNameResponse);
> 
>   rpc GetProjectChangedNotificationStream(GetProjectChangedNotificationStreamRequest) returns (stream ProjectChangedNotification);
> 
>   rpc GetViews(GetViewsRequest) returns (GetViewsResponse);
> 
>   rpc SelectView(SelectViewRequest) returns (SelectViewResponse);
> 
>   rpc SetBatchRenderView(SetBatchRenderViewRequest) returns (SetBatchRenderViewResponse);
> 
>   rpc GetProperties(GetPropertiesRequest) returns (GetPropertiesResponse);
> 
>   rpc GetProperty(GetPropertyRequest) returns (GetPropertyResponse);
> 
>   rpc SetProperty(SetPropertyRequest) returns (SetPropertyResponse);
> 
>   rpc ExportVRScene(ExportVRSceneRequest) returns (ExportVRSceneResponse);
> 
>   rpc GetVRayMaterials(GetVRayMaterialsRequest) returns (GetVRayMaterialsResponse);
> 
>   rpc SaveVRayMaterialToFile (SaveVRayMaterialToFileRequest) returns (SaveVRayMaterialToFileResponse);
> 
> }


### GetProjectName

---

> Macro (highlight)
> 
> `GetProjectName`

> Macro (highlight)
> 
> `GetProjectNameRequest`

> Macro (highlight)
> 
> `GetProjectNameResponse`

> Macro (panel)
> 
> message GetProjectNameRequest {
> 
> google.protobuf.Empty empty = 1;
> 
> }

- `GetProjectNameRequest` has no properties.

> Macro (panel)
> 
> `message GetProjectNameResponse {`
> 
> `bool success_status = 1;`  
> `string message = 2;`  
> `string project_name = 3;`
> 
> `}`

- `success_status:` A boolean indicating whether the RPC succeeded.
- `message:` A string containing an error message in case the RPC failed for some reason.
- `project_name:` The name of the project that is currently active in Revit.

### GetProjectChangedNotificationStream

---

> Macro (highlight)
> 
> `GetProjectChangedNotificationStream`

> Macro (highlight)
> 
> `GetProjectChangedNotificationStreamRequest`

> Macro (highlight)
> 
> `ProjectChangedNotification`

> Macro (panel)
> 
> `message GetProjectChangedNotificationStreamRequest {`
> 
> `google.protobuf.Empty empty = 1;`
> 
> `}`

- `GetProjectChangedNotificationStreamRequest` has no properties.

> Macro (panel)
> 
> `message ProjectChangedNotification {`
> 
> `string project_name = 1;`
> 
> `}`

- `project_name`: A string containing the name of the project that is currently active in Revit.

### GetViews

---

> Macro (highlight)
> 
> `GetViews`

> Macro (highlight)
> 
> `GetViewsRequest`

> Macro (highlight)
> 
> `GetViewsResponse`

> Macro (panel)
> 
> `message GetViewsRequest {`
> 
> `google.protobuf.Empty empty = 1;`
> 
> `}`

- `GetViewsRequest` has no properties.

> Macro (panel)
> 
> `message GetViewsResponse {`
> 
> `bool success_status = 1;`  
> `string message = 2;`  
> `ViewMap view_map = 3;`
> 
> `}`

- `success_status`: A boolean indicating whether the RPC succeeded.
- `message:` A string containing an error message in case the RPC failed for some reason.
- `view_map:` A
  containing information about all 3D Views in the active project.

> Macro (panel)
> 
> `message ViewMap {`
> 
> `map<string, View> values = 1;`
> 
> `}`

- `values:` A [map ](https://developers.google.com/protocol-buffers/docs/proto3#maps)containing all views, where the key is the unique id of the
  , and the value is the
  itself.

> Macro (panel)
> 
> `message View {`
> 
> `string unique_id = 1;`  
> `string name = 2;`  
> `bool batch_render = 3;`
> 
> `}`

- `unique_id`: A string in GUID format that represents the unique id of the view.
- `name:` A string containing the name of the view, i.e. what the user sees in Revit.
- `batch_render: `A boolean specifying whether this view will be rendered as part of Batch Render.

### SelectView

---

> Macro (highlight)
> 
> `SelectView`

> Macro (highlight)
> 
> `SelectViewRequest`

> Macro (highlight)
> 
> SelectViewResponse

> Macro (panel)
> 
> `message SelectViewRequest {`
> 
> `string unique_id = 1;`
> 
> `}`

- `unique_id:` A string in GUID format that represents the unique id of the view. This is the same string that is obtained with the

> Macro (highlight)
> 
> `GetViews`

> Macro (panel)
> 
> `message SelectViewResponse {`
> 
> `bool success_status = 1;`  
> `string message = 2;`
> 
> `}`

- `success_status:` A boolean indicating whether the RPC succeeded.
- `message:` A string containing an error message in case the RPC failed for some reason.

### **SetBatchRenderView**

> Macro (highlight)
> 
> `SetBatchRenderView`

> Macro (highlight)
> 
> `SetBatchRenderViewRequest`

> Macro (highlight)
> 
> `SetBatchRenderViewResponse`

#### **SetBatchRenderViewRequest**

> Macro (panel)
> 
> `message SetBatchRenderViewRequest {`
> 
> `string unique_id = 1;`  
> `bool batch_render = 2;`
> 
> `}`

- `unique_id:` A string in GUID format that represents the unique id of the view. This is the same string that is obtained with the `GetViews` RPC.
- `batch_render: `A boolean value specifying whether the view will be rendered in a Batch Render.

#### **SetBatchRenderViewResponse**

> Macro (panel)
> 
> `message SelectViewResponse {`
> 
> `bool success_status = 1;`  
> `string message = 2;`
> 
> `}`

- `success_status:` A boolean indicating whether the RPC succeeded.
- `message: `A string containing an error message in case the RPC failed for some reason.

### GetProperties

---

> Macro (highlight)
> 
> `GetProperties`

> Macro (highlight)
> 
> `GetPropertiesRequest`

> Macro (highlight)
> 
> `GetPropertiesResponse`

> Macro (panel)
> 
> `message GetPropertiesRequest {`
> 
> `google.protobuf.Empty empty = 1;`
> 
> `}`

- `GetPropertiesRequest` has no properties.

> Macro (panel)
> 
> `message GetPropertiesResponse {`
> 
> `bool success_status = 1;`  
> `string message = 2;`  
> `PropertyMap property_map = 3;`
> 
> `}`

- success_status: A boolean indicating whether the RPC succeeded.
- message: A string containing an error message in case the RPC failed for some reason.
- property_map: A
  containing all properties of the active project.

> Macro (panel)
> 
> `message PropertyMap {`
> 
> `map<string, Property> values = 1;`
> 
> `}`

- `values`: A [map ](https://developers.google.com/protocol-buffers/docs/proto3#maps)containing all properties, where the key is the unique name of the Property, and the value is the Property itself.

> Macro (panel)
> 
> `message Property {`
> 
> `string unique_name = 1;`  
> `string readable_name = 2;`  
> `string type = 3;`  
> `PropertyCategory category = 4;`  
> `PropertyValue value = 5;`
> 
> `}`

- `unique_name:` A string that contains the unique name of the property.
- `readable_name:` A string that contains the human-friendly readable name of the property.
- `type:` A string containing the type of the property, i.e. bool, int, string, etc.
- `category:` A PropertyCategory containing the category of the property, i.e. Camera, Environment, etc.
- `value:` A PropertyValue containing the value of the property.

> Macro (panel)
> 
> `enum PropertyCategory {`
> 
> `Global = 0;`  
> `Material = 1;`  
> `Environment = 2;`  
> `Camera = 3;`  
> `Local = 4;`  
> `Swarm = 5;`  
> `Channel = 6;`  
> `Proxy = 7;`  
> `VRayMaterial = 8;`
> 
> `};`

- `PropertyCategory` is enumeration that contains all possible property categories. Currently, the V-Ray for Revit Public API returns only properties from `Camera, Channel, Environment,` and `Local` categories.

> Macro (panel)
> 
> `message PropertyValue {`
> 
> ` oneof value `  
> ` {`
> 
> ` bool bool_value = 1;`  
> ` int32 int_value = 2;`  
> ` float float_value = 3;`  
> ` string string_value = 4;`  
>   
> ` LightingAnalysisQuantity LightingAnalysisQuantity_value = 5;`  
> ` LightingAnalysisScale LightingAnalysisScale_value = 6;`  
> ` LightingAnalysisDisplay LightingAnalysisDisplay_value = 7;`  
> ` DenoiserMode DenoiserMode_value = 8;`  
> ` DenoiserEngine DenoiserEngine_value = 9;`  
> ` DenoiserRadiusType DenoiserRadiusType_value = 10;`  
> ` VRayRenderEngine VRayRenderEngine_value = 11;`  
> ` VRayResolutionRatio VRayResolutionRatio_value = 12;`  
> ` VRayResolutionDPIType VRayResolutionDPIType_value = 13;`  
> ` VRayResolutionPrinterUnit VRayResolutionPrinterUnit_value = 14;`  
> ` EnvironmentType EnvironmentType_value = 15;`  
> ` ScreenPlacementType ScreenPlacementType_value = 16;`  
> ` BackgroundType BackgroundType_value = 17;`  
> ` VRaySceneQuality VRaySceneQuality_value = 18;`  
> ` VRayImageSamplerType VRayImageSamplerType_value = 19;`  
> ` VRayGIEngine VRayGIEngine_value = 20;`  
> ` VRayLightEvaluation VRayLightEvaluation_value = 21;`  
> ` VRayCameraMode VRayCameraMode_value = 22;`  
> ` VRayCameraStereoLayout VRayCameraStereoLayout_value = 23;`  
> ` VRayCameraFocusSource VRayCameraFocusSource_value = 24;`  
> ` LightMixGroupBy LightMixGroupBy_value = 25;`  
> ` VRaySkyModel VRaySkyModel_value = 26;`  
> ` VolumeVRayToonWidthUnits VolumeVRayToonWidthUnits_value = 27;`
> 
> `AColor AColor_value = 28;`  
> `Color Color_value = 29;`
> 
> `}`
> 
> `}`

- `value:` Contains [oneof ](https://developers.google.com/protocol-buffers/docs/proto3#oneof)the possible values for a property depending on its type.

### GetProperty

---

> Macro (highlight)
> 
> `GetProperty`

> Macro (highlight)
> 
> `GetPropertyRequest`

> Macro (highlight)
> 
> `GetPropertyResponse`

> Macro (panel)
> 
> message GetPropertyRequest {
> 
> string unique_name = 1;
> 
> }

- `unique_name:` A string that contains the unique name of the property.

> Macro (panel)
> 
> `message GetPropertyResponse {`
> 
> `bool success_status = 1;`  
> `string message = 2;`  
> `Property property = 3;`
> 
> `}`

- success_status: A boolean indicating whether the RPC succeeded.
- message: A string containing an error message in case the RPC failed for some reason.
- property: A Property instance representing the requested property.

### SetProperty

---

> Macro (highlight)
> 
> `SetProperty`

> Macro (highlight)
> 
> `SetPropertyRequest`

> Macro (highlight)
> 
> `SetPropertyResponse`

> Macro (panel)
> 
> `message SetPropertyRequest {`
> 
> `string unique_name = 1;`  
> `PropertyValue value = 2;`
> 
> `}`

- `unique_name:` A string that contains the unique name of the property.
- `value:` A PropertyValue containing the value to be set to the property.

> Macro (panel)
> 
> `message SetPropertyResponse {`
> 
> `bool success_status = 1;`  
> `string message = 2;`
> 
> `}`

- `success_status:` A boolean indicating whether the RPC succeeded.
- `message:` A string containing an error message in case the RPC failed for some reason.

### ExportVRScene

---

> Macro (highlight)
> 
> `ExportVRScene`

> Macro (highlight)
> 
> `ExportVRSceneRequest`

> Macro (highlight)
> 
> `ExportVRSceneResponse`

> Macro (panel)
> 
> `message ExportVRSceneRequest {`
> 
> `string export_file_path = 1;`  
> `bool export_compressed = 2;`  
> `bool export_hex_format = 3;`  
> `bool export_as_archive = 4;`
> 
> `}`

- `export_file_path:` A string containing the absolute path where the V-Ray Scene should be exported.
- `export_compressed:` A boolean indicating whehter to compress plugin property values of lists. Requires export_hex_format to be true.
- `export_hex_format:` A boolean indicating whether to use hex format for arrays and transforms in the V-Ray Scene.
- `export_as_archive:` A boolean indicating whether to export the V-Ray Scene as a 7-Zip archive along with all referenced assets, i.e. textures, HDRs, images, etc.

> Macro (panel)
> 
> `message ExportVRSceneResponse {`
> 
> `bool success_status = 1;`  
> `string message = 2;`
> 
> `}`

- `success_status:` A boolean indicating whether the RPC succeeded.
- `message:` If the RPC succeeded, this message would contain the actual path of the exported scene. If the RPC failed, this would be a string containing an error message.

### GetVRayMaterials

---

> Macro (highlight)
> 
> `GetVRayMaterials`

> Macro (highlight)
> 
> `GetVRayMaterialsRequest`

> Macro (highlight)
> 
> `GetVRayMaterialsResponse`

> Macro (panel)
> 
> `message GetVRayMaterialsRequest {`
> 
> `google.protobuf.Empty empty = 1;`
> 
> `}`

- `GetVRayMaterialsRequest` has no properties.

> Macro (panel)
> 
> `message GetVRayMaterialsResponse {`
> 
> bool success_status = 1;  
> string message = 2;  
> repeated string material_names = 3;
> 
> }

- success_status: A boolean indicating whether the RPC succeeded.
- message: A string containing an error message in case the RPC failed for some reason.
- material_names: A [repeated](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/collections/repeated-field-t-) string field containing the names of all V-Ray materials in the project.

### SaveVRayMaterialToFile

---

> Macro (highlight)
> 
> `SaveVRayMaterialToFile`

> Macro (highlight)
> 
> `SaveVRayMaterialToFileRequest`

> Macro (highlight)
> 
> `SaveVRayMaterialToFileResponse`

> Macro (highlight)
> 
> `maps`

> Macro (highlight)
> 
> `maps`

> Macro (panel)
> 
> `message SaveVRayMaterialToFileRequest {`
> 
> `string material_name = 1;`  
> `string file_path = 2;`
> 
> `}`

- `material_name:` A string containing the name of the V-Ray material that should be saved.
- `file_path:` A string containing the absolute path where the V-Ray Material should be saved.

> Macro (panel)
> 
> `message SaveVRayMaterialToFileResponse {`
> 
> bool success_status = 1;  
> string message = 2;
> 
> `}`

- `success_status:` A boolean indicating whether the RPC succeeded.
- `message:` If the RPC failed, this would be a string containing an error message.

### Enums and custom types

---

> Macro (panel)
> 
> `enum LightingAnalysisQuantity {`
> 
> `LuminanceCD = 0;`  
> `IlluminanceLX = 1;`
> 
> `}`

- `LuminanceCD:` Uses the Illuminance of the rendered frame in lux.
- `IlluminanceLX:` Uses the Luminance of the rendered frame in candelas.

> Macro (panel)
> 
> `enum LightingAnalysisScale {`
> 
> `Linear = 0;`  
> `Logarithmic = 1;`
> 
> `}`

- `Linear:` The colors are mapped in linear scale.
- `Logarithmic:` The colors are mapped in logarithmic scale.

> Macro (panel)
> 
> `enum LightingAnalysisDisplay {`
> 
> `FalseColors = 0;`  
> `GridOverlay = 1;`
> 
> `}`

- `FalseColors:` Fills the frame with a gradient ranging from blue (low values) to red (high values). For the out of range values it uses, respectively, black and white.
- `GridOverlay:` Displays the values at distinct grid points over the frame. They use the same grading colors.

> Macro (panel)
> 
> `enum DenoiserMode {`
> 
> `ReplaceRGB = 0;`  
> `DoNotCalculate = 1;`  
> `GenerateChannel = 2;`
> 
> `}`

- `ReplaceRGB:` Generates all render elements required for denoising, but does not compute a denoised version of the image, neither is the VRayDenoiser render element present.
- `DoNotCalculate:` The VRayDenoiser channel is not present separately in the VFB. The effectsResult channel is generated with the denoised image.
- `GenerateChannel:` The VRayDenoiser and effectsResult channels are generated.

> Macro (panel)
> 
> `enum DenoiserEngine {`
> 
> `Default = 0;`  
> `NVIDIA = 1;`
> 
> `}`

- `Default:` Default V-Ray Denoiser
- `NVIDIA:` NVidia Al Denoiser

> Macro (panel)
> 
> `enum DenoiserRadiusType {`
> 
> `CustomType = 0;`  
> `Mild = 1;`  
> `Normal = 2;`  
> `Strong = 3;`
> 
> `}`

- `CustomType:` Allows the strength and radius parameters to be set to custom values.
- `Mild:` Applies a subtler level of denoising than the Default preset.
- `Normal:` Applies default denoising.
- `Strong:` Applies a stronger level of denoising than the Default preset.

> Macro (panel)
> 
> `enum VRayRenderEngine {`
> 
> `CPU = 0;`  
> `GPU = 4;`  
> `RTX = 7;`
> 
> `}`

- `CPU:` CPU
- `GPU:` CUDA(GPU)
- `RTX:` RTX(GPU)

> Macro (panel)
> 
> `enum VRayResolutionRatio {`
> 
> `Widescreen = 0;`  
> `Screen = 1;`  
> `Square = 2;`  
> `Picture = 3;`  
> `Landscape = 4;`  
> `Portrait = 5;`  
> `CropRegion = 6;`  
> `Custom = 7;`
> 
> `}`

- `Widescreen:` 16:9 - Widescreen
- `Screen:` 8:5 - Screen
- `Square:` 1:1 - Square
- `Picture:` 4:3 - Picture
- `Landscape:` 5:4 - Landscape
- `Portrait:` 4:5 - Portrait
- `CropRegion:` The default Aspect Ratio, which allows for rendering the exact boundary of Revit’s Crop Region.
- `Custom:` Allows manual input of the proportions of the image.

> Macro (panel)
> 
> `enum VRayResolutionDPIType {`
> 
> `UnusedVRayResolutionDPIType = 0;`  
> `DPI75 = 75;`  
> `DPI96 = 96;`  
> `DPI150 = 150;`  
> `DPI300 = 300;`  
> `DPI600 = 600;`
> 
> `}`

- `DPI75:` 75 dpi
- `DPI96:` 96 dpi
- `DPI150:` 150 dpi
- `DPI300:` 300 dpi
- `DPI600:` 600 dpi

> Macro (panel)
> 
> `enum VRayResolutionPrinterUnit {`
> 
> `Inches = 0;`  
> `Millimeters = 1;`
> 
> `}`

- `Inches:` Inches
- `Millimeters:` Millimeters

> Macro (panel)
> 
> `enum EnvironmentType {`
> 
> Sun = 0;  
> Dome = 1;  
> None = 2;
> 
> `}`

- `Sun:` V-Ray Sun
- `Dome:` V-Ray Dome Light
- `None:` No V-Ray Lights

> Macro (panel)
> 
> `enum ScreenPlacementType {`
> 
> ScreenPlacement = 0;  
> SphericalPlacement = 1;
> 
> `}`

- `ScreenPlacement:` Screen Placement
- `SphericalPlacement:` SphericalPlacement

> Macro (panel)
> 
> `enum BackgroundType {`
> 
> NoBackground = 0;  
> CustomBackground = 1;  
> RevitBackground = 2;
> 
> `}`

- `NoBackground:` No Background
- `CustomBackground:` Custom Background
- `RevitBackground:` Revit Background

> Macro (panel)
> 
> `enum VRaySceneQuality {`
> 
> Draft = 0;  
> Low = 1;  
> Medium = 2;  
> High = 3;  
> VeryHigh = 4;
> 
> `}`

- `Draft:` Draft Quality
- `Low:` Low Quality
- `Medium:` Medium Quality
- `High:` High Quality
- `VeryHigh:` VeryHigh Quality

> Macro (panel)
> 
> `enum VRayImageSamplerType  {`
> 
> UnusedVRayImageSamplerType = 0;  
> Buckets = 1;  
> Progressive = 3;
> 
> `}`

- `UnusedVRayImageSamplerType:` NEVER USE THIS VALUE. IT WAS INTRODUCED DUE TO PROTO SYNTAX LIMITATIONS.
- `Buckets:` This sampler takes a variable number of samples per pixel based on the difference in intensity between the pixel and its neighbors.
- `Progressive:` This is the default image sampler set in V-Ray for Revit. It renders the entire image progressively in passes.

> Macro (panel)
> 
> `enum VRayGIEngine {`
> 
> IrradianceMap = 0;  
> BruteForce = 2;  
> LightCache = 3;
> 
> `}`

- `IrradianceMap:` Indirect Illumination is computed for a few points in a scene. The remaining points use interpolated values. It is built adaptively but is view-dependent.
- `BruteForce:` The simplest approach where indirect illumination is computed individually for each shaded surface point.
- `LightCache:` Traces multiple paths from the camera. It is view-dependent, but handles details and corners better.

> Macro (panel)
> 
> `enum VRayLightEvaluation {`
> 
> Full = 0;  
> Adaptive = 2;
> 
> `}`

- `Full:` Full light evaluation.
- `Adaptive:` Optimizes the sampling of lights in scenes with many lights.

> Macro (panel)
> 
> `enum VRayCameraMode {`
> 
> Standard = 0;  
> Orthogonal = 7;  
> SphericalPanorama = 9;  
> Cube = 10;
> 
> `}`

- `Standard:` A traditional pinhole camera.
- `Orthogonal:` An orthogonal camera.
- `SphericalPanorama:` Spherical camera with independent horizontal and vertical FOV selection that is useful for generating latlong images for spherical VR use.
- `Cube:` A variant of the Box camera with the cube sides arranged in a single row. Unlike the Box camera output, Cube6x1 does not produce an empty space in the output image and is useful for generating cubic VR output.

> Macro (panel)
> 
> `enum VRayCameraStereoLayout {`
> 
> UnusedVRayCameraStereoLayout = 0;  
> SideBySide = 1;  
> TopBottom = 2;
> 
> `}`

- `UnusedVRayCameraStereoLayout:` NEVER USE THIS VALUE. IT WAS INTRODUCED DUE TO PROTO SYNTAX LIMITATIONS.
- `SideBySide:` Stereoscopic images are rendered Side-by-side.
- `TopBottom:` Stereoscopic images are rendered Top-bottom.

> Macro (panel)
> 
> `enum VRayCameraFocusSource {`
> 
> FixedDistance = 0;  
> FixedPoint = 2;
> 
> `}`

- `FixedDistance:` Fixes the camera focus to the Focus Distance value.
- `FixedPoint:` The focus distance is automatically calculated before the rendering starts, and equals the distance between the camera position and the 3D point selected using the Pick Focus Point Command from the toolbar menu. If no point has been selected, the camera target is used as a default point instead.

#### **LightMixGroupBy**  


> Macro (panel)
> 
> `enum LightMixGroupBy {`
> 
> FamilyType = 0;  
> IndividualLights = 1;  
> LightGroups = 2;
> 
> `}`

- `FamilyType:` All instances of the same family type are put in a separate Light Select.
- `IndividualLights:` Each light goes to a separate Light Select.
- `LightGroups:` Separate Light Select for each group of lights.

#### **VRaySkyModel**

> ℹ️ `enum VRaySkyModel {`
> ℹ️ 
> ℹ️ Preetham = 0;  
> ℹ️ CIEClear = 1;  
> ℹ️ CIEOvercast = 2;  
> ℹ️ Hosek = 3;  
> ℹ️ Improved = 4;
> ℹ️ 
> ℹ️ `}`

- `Preetham:` V-Ray Sky procedural texture is generated based on the Preetham et al. method. (UI label: Preetham et al.)
- `CIEClear:` V-Ray Sky procedural texture is generated based on the CIE method for clear sky. (UI label: CIE Clear)
- `CIEOvercast:` V-Ray Sky procedural texture is generated based on the CIE method for cloudy sky. (UI label: CIE Overcast)
- `Hosek:` V-Ray Sky procedural texture is generated based on the Hosek et al. method. (UI label: Hosek et al.)
- `Improved:` V-Ray Sky procedural texture is generated based on the Improved method which has enhanced sunrise and sunset sky. (UI label: PRG Clear Sky)

#### **VolumeVRayToonWidthUnits**

> ℹ️ `enum VolumeVRayToonWidthUnits `
> ℹ️ 
> ℹ️ Pixels = 0;  
> ℹ️ Project = 1;
> ℹ️ 
> ℹ️ `}`

- `Pixels:` Specifies that all of the Contour parameters are considered in pixels.
- `Project:` Specifies that all of the Contour parameters are considered in the project units.

> Macro (panel)
> 
> `message AColor {`
> 
> float r = 1;  
> float g = 2;  
> float b = 3;  
> float alpha = 4;
> 
> `}`

- `r`: Value between 0.0 and 1.0 for the red color.
- `g`: Value between 0.0 and 1.0 for the green color.
- `b`: Value between 0.0 and 1.0 for the blue color.
- `alpha:` Value between 0.0 and 1.0 for the alpha.

> Macro (panel)
> 
> `message Color {`
> 
> float r = 1;  
> float g = 2;  
> float b = 3;
> 
> `}`

- `r`: Value between 0.0 and 1.0 for the red color.
- `g`: Value between 0.0 and 1.0 for the green color.
- `b`: Value between 0.0 and 1.0 for the blue color.

## **Code Samples (C#)**

---

### Obtaining the Server Port

> Macro (highlight)
> 
> C:\Users\%USERPROFILE%\AppData\Roaming\Chaos\V-Ray for Revit 20##\config.json

> Macro (highlight)
> 
> `##`

> Macro (highlight)
> 
> `apiServers`

> Macro (panel)
> 
> "apiServers": [
> 
> {
> 
> "PID": 22920,  
> "port": 58538
> 
> },  
> {
> 
> "PID": 14792,  
> "port": 58611
> 
> }
> 
> ]

> Macro (panel)
> 
> private const int RevitVersion = 2020;  
> private static readonly string ConfigJsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
> 
> $"Chaos \\V-Ray for Revit {RevitVersion}", "config.json");
> 
> private static int GetServerPort()
> 
> {
> 
> var runningInRevitAddon = true;
> 
> using (var reader = new StreamReader(ConfigJsonPath))  
> {
> 
> var json = JObject.Parse(reader.ReadToEnd());
> 
> var apiServers = json["apiServers"] as JArray;  
>   
> if (apiServers != null && apiServers.Count > 0)  
> {
> 
> JObject apiServer;  
> if (runningInRevitAddon)  
> {
> 
> apiServer = apiServers.OfType<JObject>().SingleOrDefault(jo => (int)jo["PID"] == Process.GetCurrentProcess().Id);
> 
> }  
> else  
> {
> 
> apiServer = apiServers.OfType<JObject>().FirstOrDefault();
> 
> }
> 
> if (apiServer != null)  
> {
> 
> return (int)apiServer["port"];
> 
> }
> 
> }
> 
> }
> 
> return -1;
> 
> }

> Macro (highlight)
> 
> `config.json`

### Connecting to the Server

---

> Macro (panel)
> 
> public async Task<bool> ConnectAsync()
> 
> {
> 
> var serverPort = GetServerPort();  
> if (serverPort != -1)  
> {
> 
> this.channel = new Channel($"localhost:{serverPort}", ChannelCredentials.Insecure);
> 
> var deadline = DateTime.UtcNow.AddSeconds(1);  
> try  
> {
> 
> await this.channel.ConnectAsync(deadline);
> 
> return true;
> 
> }  
> catch (TaskCanceledException)  
> {
> 
> return false;
> 
> }
> 
> }  
> else  
> {
> 
> Debug.WriteLine("Public API Server has not started yet!");  
> return false;
> 
> }
> 
> }

> Macro (highlight)
> 
> `GetServerPort`

### Get the active project name

---

> Macro (panel)
> 
> public async Task<string> GetProjectNameAsync()  
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);  
> var response = await client.GetProjectNameAsync(new GetProjectNameRequest());  
> if (response.SuccessStatus)  
> {
> 
> return response.ProjectName;
> 
> }  
> else  
> {
> 
> MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);  
> return string.Empty;
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);  
> return string.Empty;
> 
> }
> 
> }

> Macro (highlight)
> 
> `ApiServerClient`

> Macro (highlight)
> 
> `GetProjectNameRequest`

> Macro (highlight)
> 
> `GetProjectNameResponse`

### Get all 3D Views from the active project

---

> Macro (panel)
> 
> public async Task<IEnumerable<View>> GetViewsAsync()  
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);  
> var response = await client.GetViewsAsync(new GetViewsRequest());  
> if (response.SuccessStatus)  
> {
> 
> return response.ViewMap.Values.Values;
> 
> }  
> else  
> {
> 
> MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);  
> return Enumerable.Empty<View>();
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);  
> return Enumerable.Empty<View>();
> 
> }
> 
> }

> Macro (highlight)
> 
> `ApiServerClient`

> Macro (highlight)
> 
> `GetViewsRequest`

> Macro (highlight)
> 
> `GetViewsResponse`

### Select a 3D View

---

> Macro (panel)
> 
> public async Task<bool> SelectViewAsync(string uniqueId)  
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);  
> var response = await client.SelectViewAsync(new SelectViewRequest() { UniqueId = uniqueId });  
>   
> if (response.SuccessStatus)  
> {
> 
> return true;
> 
> }  
> else  
> {
> 
> MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);  
> return false;
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);  
> return false;
> 
> }
> 
> }

> Macro (highlight)
> 
> `uniqueId`

### **Set Batch Render for a 3D View**

---

> Macro (panel)
> 
> public async Task<bool> SetBatchRenderViewAsync(string uniqueId, bool batchRender)  
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);  
> var response = await client.SetBatchRenderViewAsync(new SetBatchRenderViewRequest() { UniqueId = uniqueId, BatchRender = batchRender });  
> if (response.SuccessStatus)  
> {
> 
> return true;
> 
> }  
> else  
> {
> 
> MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error)  
> return false;
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);  
> return false;
> 
> }
> 
> }

> Macro (highlight)
> 
> `uniqueId`

> Macro (highlight)
> 
> `batchRender`

### Get all properties

---

> Macro (panel)
> 
> public async Task<IEnumerable<Property>> GetPropertiesAsync()  
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);  
> var response = await client.GetPropertiesAsync(new GetPropertiesRequest());  
> if (response.SuccessStatus)  
> {
> 
> return response.PropertyMap.Values.Values;
> 
> }  
> else  
> {
> 
> MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);  
> return Enumerable.Empty<Property>();
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);  
> return Enumerable.Empty<Property>();
> 
> }
> 
> }

> Macro (highlight)
> 
> `ApiServerClient`

> Macro (highlight)
> 
> `GetPropertiesRequest`

> Macro (highlight)
> 
> `GetPropertiesResponse`

### Get a single property

---

> Macro (panel)
> 
> public async Task<Property> GetPropertyAsync(string uniqueName)  
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);  
> var response = await client.GetPropertyAsync(new GetPropertyRequest() { UniqueName = uniqueName });  
> if (response.SuccessStatus)  
> {
> 
> return response.Property;
> 
> }  
> else  
> {
> 
> MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);  
> return null;
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);  
> return null;
> 
> }
> 
> }

> Macro (highlight)
> 
> `uniqueName`

### Set property

---

> Macro (panel)
> 
> public async Task<bool> SetPropertyAsync(string uniqueName, PropertyValue propertyValue)  
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);  
>   
> var request = new SetPropertyRequest()  
> {
> 
> UniqueName = uniqueName,  
> Value = propertyValue
> 
> };  
>   
> var response = await client.SetPropertyAsync(request);  
>   
> if (response.SuccessStatus)  
> {
> 
> return true;
> 
> }  
> else  
> {
> 
> MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);  
> return false;
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);  
> return false;
> 
> }
> 
> }

> Macro (highlight)
> 
> `uniqueName`

> Macro (highlight)
> 
> `Get all properties`

> Macro (highlight)
> 
> `propertyValue`

> Macro (highlight)
> 
> `PropertyValue`

###   
Set bool property

---

> Macro (panel)
> 
> `var uniqueName = "GlobalArtificialLightsEnabled";`  
> `var propertyValue = new PropertyValue() { BoolValue = true };`  
> `SetPropertyAsync(uniqueName, propertyValue);`

### Set int property

---

> Macro (panel)
> 
> `var uniqueName = "customResolutionWidth";`  
> `var propertyValue = new PropertyValue() { IntValue = 800 };`  
> `SetPropertyAsync(uniqueName, propertyValue);`

### Set float property

---

> Macro (panel)
> 
> `var uniqueName = "GlobalArtificialLightsIntensity";`  
> `var propertyValue = new PropertyValue() { FloatValue = 2.0f };`  
> `SetPropertyAsync(uniqueName, propertyValue);`

### Set string property

---

> Macro (panel)
> 
> `var uniqueName = "backgroundImagePath";`  
> `var propertyValue = new PropertyValue() { StringValue = "C:\myimage.png" };`  
> `SetPropertyAsync(uniqueName, propertyValue);`

### Set enum property

---

> Macro (panel)
> 
> `var uniqueName = "environmentType";`  
> `var propertyValue = new PropertyValue() { EnvironmentTypeValue = EnvironmentType.Dome };`  
> `SetPropertyAsync(uniqueName, propertyValue);`

### Set AColor property

---

> Macro (panel)
> 
> `var uniqueName = "EnvFogColor";`  
> `var propertyValue = new PropertyValue() { AColorValue = new AColor() { R = 0.5f, G = 0.5f, B = 0.5f, Alpha = 1.0f } };`  
> `SetPropertyAsync(uniqueName, propertyValue);`

### Set Color property

---

> Macro (panel)
> 
> `var uniqueName = "SunFilterColor";`  
> `var propertyValue = new PropertyValue() { ColorValue = new Color() { R = 0.5f, G = 0.5f, B = 0.5f } };`  
> `SetPropertyAsync(uniqueName, propertyValue);`

### Export V-Ray Scene

---

> Macro (panel)
> 
> public async Task<Tuple<bool, string>> ExportVRSceneAsync(string exportFilePath, bool exportAsArchive, bool exportCompressed, bool exportHexFormat)
> 
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);  
> try  
> {
> 
> var response = await client.ExportVRSceneAsync(new ExportVRSceneRequest()  
> {
> 
> ExportFilePath = exportFilePath,  
> ExportAsArchive = exportAsArchive,  
> ExportCompressed = exportCompressed,  
> ExportHexFormat = exportHexFormat
> 
> });
> 
> // If the export was successfull, response.Message will contain the  
> // actual file path of the exported V-Ray Scene  
> return new Tuple<bool, string>(response.SuccessStatus, response.Message);
> 
> }  
> catch (TaskCanceledException e)  
> {
> 
> Debug.WriteLine(e);  
> return new Tuple<bool, string>(false, e.ToString());
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);  
> await this.ShutdownAsync();  
> return new Tuple<bool, string>(false, e.ToString());
> 
> }
> 
> }

> Macro (highlight)
> 
> `ApiServerClient`

> Macro (highlight)
> 
> `ExportVRSceneRequest`

> Macro (highlight)
> 
> `ExportVRSceneResponse`

###   
Get all V-Ray Material Names

---

> Macro (panel)
> 
> public async Task<IEnumerable<string>> GetVRayMaterialsAsync()  
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);
> 
> var response = await client.GetVRayMaterialsAsync(new GetVRayMaterialsRequest());  
> if (response.SuccessStatus)  
> {
> 
> return response.MaterialNames;
> 
> }  
> else  
> {
> 
> MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);  
> return Enumerable.Empty<string>();
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);  
> return Enumerable.Empty<string>();
> 
> }
> 
> }

> Macro (highlight)
> 
> `ApiServerClient`

> Macro (highlight)
> 
> `GetVRayMaterialsRequest`

> Macro (highlight)
> 
> `GetVRayMaterialsResponse`

###   
Save V-Ray Material to File

---

> Macro (panel)
> 
> public async Task<Tuple<bool, string>> SaveVRayMaterialToFileAsync(string materialName, string filePath)
> 
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);  
> try  
> {
> 
> var response = await client.SaveVRayMaterialToFileAsync(new SaveVRayMaterialToFileRequest()  
> {
> 
> MaterialName = materialName,  
> FilePath = filePath
> 
> });
> 
> return new Tuple<bool, string>(response.SuccessStatus, response.Message);
> 
> }  
> catch (TaskCanceledException e)  
> {
> 
> Debug.WriteLine(e);  
> return new Tuple<bool, string>(false, e.ToString());
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);  
> return new Tuple<bool, string>(false, e.ToString());
> 
> }
> 
> }

> Macro (highlight)
> 
> `ApiServerClient`

> Macro (highlight)
> 
> `SaveVRayMaterialToFileRequest`

> Macro (highlight)
> 
> `SaveVRayMaterialToFileResponse`

###   
Listen for project changed

---

> Macro (panel)
> 
> public async void ListenForProjectChangedAsync()  
> {
> 
> try  
> {
> 
> var client = new ApiServerClient(this.channel);
> 
> using (var call = client.GetProjectChangedNotificationStream(new GetProjectChangedNotificationStreamRequest(), null, null, this.cts.Token))  
> {
> 
> while (await call.ResponseStream.MoveNext())  
> {
> 
> var projectName = call.ResponseStream.Current.ProjectName;  
> Debug.WriteLine("Project has changed to " + projectName);
> 
> }
> 
> }
> 
> }  
> catch (RpcException e)  
> {
> 
> Debug.WriteLine(e);
> 
> }
> 
> }

## **Resources**

---

- [Task Parallel Library (TPL)](https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/task-parallel-library-tpl)
- [https://grpc.io/](https://grpc.io/)
- [https://grpc.io/docs/languages/csharp/quickstart/](https://grpc.io/docs/languages/csharp/quickstart/)
- [https://grpc.io/docs/languages/csharp/basics/](https://grpc.io/docs/languages/csharp/basics/)
- [https://grpc.github.io/grpc/csharp/api/Grpc.Core](https://grpc.github.io/grpc/csharp/api/Grpc.Core)
- [https://www.nuget.org/packages/Grpc.Tools/](https://www.nuget.org/packages/Grpc.Tools/)
- [https://github.com/grpc](https://github.com/grpc)

## **V-Ray for Revit Public API Client Reference Implementation**

---

> Macro (ui-text-box)
> 
> For versions prior to V-Ray 7, the default location of the reference implementation of a C# client is C:\Program Files\Chaos Group\V-Ray\V-Ray for Revit\PublicAPIClient.zip.

![image](media://cd8b59ea-7dfd-4483-8e9d-561771183441)

## **Copyrights**

---