This page provides information about V-Ray for Revit Public APIs.
Overview
V-Ray for Revit Public API is a gRPC server application that allows clients to programmatically read and configure V-Ray for Revit's properties and export V-Ray Scenes.
Download V-Ray for Revit Public Api Documentation
Download Public API Client zip
Service Definition (public_api.proto)
V-Ray for Revit Public API provides the public_api.proto
file, which represents the service definition and protocol format. Alongside the .proto file, two auto-generated C# files are provided - PublicApi.cs
and PublicApiGrpc.cs
. These two files contain the C# classes for all requests, responses, messages, and enums. The public_api.proto can be used to generate a binding in a language different from C# and develop a client in any of the supported languages.
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
GetProjectName
is a unary RPC that sends a single GetProjectNameRequest
to the server and gets a single GetProjectNameResponse
back. It is used to obtain the name of the currently active project in Revit.
GetProjectNameRequest
message GetProjectNameRequest {
google.protobuf.Empty empty = 1;
}
GetProjectNameRequest
has no properties.
GetProjectNameResponse
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
GetProjectChangedNotificationStream
is a server streaming RPCs where the client sends a GetProjectChangedNotificationStreamRequest
to the server and gets a stream to read a sequence of ProjectChangedNotification
messages back. It is used to receive a notification each time the active project in Revit changes.
GetProjectChangedNotificationStreamRequest
message GetProjectChangedNotificationStreamRequest {
google.protobuf.Empty empty = 1;
}
GetProjectChangedNotificationStreamRequest
has no properties.
ProjectChangedNotification
message ProjectChangedNotification {
string project_name = 1;
}
project_name
: A string containing the name of the project that is currently active in Revit.
GetViews
GetViews
is a unary RPC that sends a single GetViewsRequest
to the server and gets a single GetViewsResponse
back. It is used to obtain the names and unique ids of all 3D Views in the project. This information is later used when selecting a view for export.
GetViewsRequest
message GetViewsRequest {
google.protobuf.Empty empty = 1;
}
GetViewsRequest
has no properties.
GetViewsResponse
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:
AViewMap
containing information about all 3D Views in the active project.
ViewMap
message ViewMap {
map<string, View> values = 1;
}
values:
A map containing all views, where the key is the unique id of theView
, and the value is theView
itself.
View
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
SelectView
is a unary RPC that sends a single SelectViewRequest
to the server and gets a single SelectViewResponse back. It is used to select a view before exporting a V-Ray Scene.
SelectViewRequest
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
GetViews
RPC.
SelectViewResponse
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
SetBatchRenderView
is a unary RPC that sends a single SetBatchRenderViewRequest
to the server and gets a single SetBatchRenderViewResponse
back. It is used to specify whether the view will be rendered in a Batch Render.
SetBatchRenderViewRequest
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 theGetViews
RPC.batch_render:
A boolean value specifying whether the view will be rendered in a Batch Render.
SetBatchRenderViewResponse
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
GetProperties
is a unary RPC that sends a single GetPropertiesRequest
to the server and gets a single GetPropertiesResponse
back. It is used to get all V-Ray properties for the active project.
GetPropertiesRequest
message GetPropertiesRequest {
google.protobuf.Empty empty = 1;
}
GetPropertiesRequest
has no properties.
GetPropertiesResponse
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
PropertyMap
containing all properties of the active project.
PropertyMap
message PropertyMap {
map<string, Property> values = 1;
}
values
: A map containing all properties, where the key is the unique name of the Property, and the value is the Property itself.
Property
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.
PropertyCategory
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 fromCamera, Channel, Environment,
andLocal
categories.
PropertyValue
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 the possible values for a property depending on its type.
GetProperty
GetProperty
is a unary RPC that sends a single GetPropertyRequest
to the server and gets a single GetPropertyResponse
back. It is used to get a single V-Ray property from the active project.
GetPropertyRequest
message GetPropertyRequest {
string unique_name = 1;
}
unique_name:
A string that contains the unique name of the property.
GetPropertyResponse
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
SetProperty
is a unary RPC that sends a single SetPropertyRequest
to the server and gets a single SetPropertyResponse
back. It is used to set a single V-Ray property in the active project.
SetPropertyRequest
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.
SetPropertyResponse
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
ExportVRScene
is a unary RPC that sends a single ExportVRSceneRequest
to the server and gets a single ExportVRSceneResponse
back. It is used to export a V-Ray Scene of the currently selected 3D View.
ExportVRSceneRequest
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.
ExportVRSceneResponse
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
GetVRayMaterials
is a unary RPC that sends a single GetVRayMaterialsRequest
to the server and gets a single GetVRayMaterialsResponse
back. It is used to obtain the names of all V-Ray materials in the project. This information is later used when saving a V-Ray material to a .vrmat file.
GetVRayMaterialsRequest
message GetVRayMaterialsRequest {
google.protobuf.Empty empty = 1;
}
GetVRayMaterialsRequest
has no properties.
GetVRayMaterialsResponse
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 string field containing the names of all V-Ray materials in the project.
SaveVRayMaterialToFile
SaveVRayMaterialToFile
is a unary RPC that sends a single SaveVRayMaterialToFileRequest
to the server and gets a single SaveVRayMaterialToFileResponse
back. It is used to save a V-Ray material along with all of its assets to the file system. When the material is saved, a folder named maps
appears next to the .vrmat file. This folder contains all assets, i.e. textures, used by the material. Always keep the maps
folder and the .vrmat file in the same folder.
SaveVRayMaterialToFileRequest
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.
SaveVRayMaterialToFileResponse
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
LightingAnalysisQuantity
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.
LightingAnalysisScale
enum LightingAnalysisScale {
Linear = 0;
Logarithmic = 1;
}
Linear:
The colors are mapped in linear scale.Logarithmic:
The colors are mapped in logarithmic scale.
LightingAnalysisDisplay
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.
DenoiserMode
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.
DenoiserEngine
enum DenoiserEngine {
Default = 0;
NVIDIA = 1;
}
Default:
Default V-Ray DenoiserNVIDIA:
NVidia Al Denoiser
DenoiserRadiusType
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.
VRayRenderEngine
enum VRayRenderEngine {
CPU = 0;
GPU = 4;
RTX = 7;
}
CPU:
CPUGPU:
CUDA(GPU)RTX:
RTX(GPU)
VRayResolutionRatio
enum VRayResolutionRatio {
Widescreen = 0;
Screen = 1;
Square = 2;
Picture = 3;
Landscape = 4;
Portrait = 5;
CropRegion = 6;
Custom = 7;
}
Widescreen:
16:9 - WidescreenScreen:
8:5 - ScreenSquare:
1:1 - SquarePicture:
4:3 - PictureLandscape:
5:4 - LandscapePortrait:
4:5 - PortraitCropRegion:
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.
VRayResolutionDPIType
enum VRayResolutionDPIType {
UnusedVRayResolutionDPIType = 0;
DPI75 = 75;
DPI96 = 96;
DPI150 = 150;
DPI300 = 300;
DPI600 = 600;
}
UnusedVRayResolutionDPIType: NEVER USE THIS VALUE. IT WAS INTRODUCED DUE TO PROTO SYNTAX LIMITATIONS.
DPI75:
75 dpiDPI96:
96 dpiDPI150:
150 dpiDPI300:
300 dpiDPI600:
600 dpi
VRayResolutionPrinterUnit
enum VRayResolutionPrinterUnit {
Inches = 0;
Millimeters = 1;
}
Inches:
InchesMillimeters:
Millimeters
EnvironmentType
enum EnvironmentType {
Sun = 0;
Dome = 1;
None = 2;
}
Sun:
V-Ray SunDome:
V-Ray Dome LightNone:
No V-Ray Lights
ScreenPlacementType
enum ScreenPlacementType {
ScreenPlacement = 0;
SphericalPlacement = 1;
}
ScreenPlacement:
Screen PlacementSphericalPlacement:
SphericalPlacement
BackgroundType
enum BackgroundType {
NoBackground = 0;
CustomBackground = 1;
RevitBackground = 2;
}
NoBackground:
No BackgroundCustomBackground:
Custom BackgroundRevitBackground:
Revit Background
VRaySceneQuality
enum VRaySceneQuality {
Draft = 0;
Low = 1;
Medium = 2;
High = 3;
VeryHigh = 4;
}
Draft:
Draft QualityLow:
Low QualityMedium:
Medium QualityHigh:
High QualityVeryHigh:
VeryHigh Quality
VRayImageSamplerType
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.
VRayGIEngine
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.
VRayLightEvaluation
enum VRayLightEvaluation {
Full = 0;
Adaptive = 2;
}
Full:
Full light evaluation.Adaptive:
Optimizes the sampling of lights in scenes with many lights.
VRayCameraMode
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.
VRayCameraStereoLayout
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.
VRayCameraFocusSource
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
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.
AColor
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.
Color
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
In order to connect to the Public API Server, the client needs to know which port the server is running on. When the the V-Ray for Revit Public API Server starts, it chooses a random free port to start on and writes this information in the C:\Users\%USERPROFILE%\AppData\Roaming\Chaos Group\V-Ray for Revit 20XX\config.json, where XX
is the Revit version. When your code is running from within a Revit Addin, use the current process id (i.e. of Revit.exe) to locate the V-Ray for Revit API Server running in the same instance of Revit.exe. When your code is running from a standalone application (console app, WPF app, etc.) and there is more than one instance of the same Revit.exe version running, it is up to you to decide to which instance of V-Ray for Revit API Server to connect to.
Here is how the apiServers
entry might look like in config.json:
"apiServers": [
{
"PID": 22920,
"port": 58538
},
{
"PID": 14792,
"port": 58611
}
]
And here is how you can obtain the port, depending on whether your code is executing from within a Revit Addin or from standalone application:
private const int RevitVersion = 2020;
private static readonly string ConfigJsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
$"Chaos Group\\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;
}
When the Public API Server is shutdown, i.e. the user closes Revit, its entry is deleted from config.json
.
Note that the code above uses the Newtonsoft Json.NET library, but you can read the json file in any way that you prefer.
Connecting to the Server
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;
}
}
GetServerPort
is from the previous code snippet.
Get the active project name
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;
}
}
ApiServerClient
, GetProjectNameRequest
, and GetProjectNameResponse
are all classes auto-generated by the proto-buffer compiler.
Get all 3D Views from the active project
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>();
}
}
ApiServerClient
, GetViewsRequest
, and GetViewsResponse
are all classes auto-generated by the proto-buffer compiler.
Select a 3D View
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;
}
}
uniqueId
is one of the unique ids of the views retrieved in the previous code snippet.
Set Batch Render for a 3D View
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;
}
}
uniqueId
is one of the unique ids of the views retrieved in the GetViews code snippet. batchRender
is a boolean value specifying whether the view will be rendered in a Batch Render.
Get all properties
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>();
}
}
ApiServerClient
, GetPropertiesRequest
, and GetPropertiesResponse
are all classes auto-generated by the proto-buffer compiler.
Get a single property
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;
}
}
uniqueName
is one of the unique names of the properties retrieved in the previous code snippet.
Set property
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;
}
}
uniqueName
is one of the unique names of the properties retrieved in the Get all properties
code snippet. propertyValue
is a PropertyValue
initialized with the correct type of value, based on the property type. The 7 code snippets below use the method defined in this code snippet.
Set bool property
var uniqueName = "GlobalArtificialLightsEnabled";
var propertyValue = new PropertyValue() { BoolValue = true };
SetPropertyAsync(uniqueName, propertyValue);
Set int property
var uniqueName = "customResolutionWidth";
var propertyValue = new PropertyValue() { IntValue = 800 };
SetPropertyAsync(uniqueName, propertyValue);
Set float property
var uniqueName = "GlobalArtificialLightsIntensity";
var propertyValue = new PropertyValue() { FloatValue = 2.0f };
SetPropertyAsync(uniqueName, propertyValue);
Set string property
var uniqueName = "backgroundImagePath";
var propertyValue = new PropertyValue() { StringValue = "C:\myimage.png" };
SetPropertyAsync(uniqueName, propertyValue);
Set enum property
var uniqueName = "environmentType";
var propertyValue = new PropertyValue() { EnvironmentTypeValue = EnvironmentType.Dome };
SetPropertyAsync(uniqueName, propertyValue);
Set AColor property
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
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
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());
}
}
ApiServerClient
, ExportVRSceneRequest
, and ExportVRSceneResponse
are all classes auto-generated by the proto-buffer compiler.
Get all V-Ray Material Names
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>();
}
}
ApiServerClient
, GetVRayMaterialsRequest
, and GetVRayMaterialsResponse
are all classes auto-generated by the proto-buffer compiler.
Save V-Ray Material to File
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());
}
}
ApiServerClient
, SaveVRayMaterialToFileRequest
, and SaveVRayMaterialToFileResponse
are all classes auto-generated by the proto-buffer compiler.
Listen for project changed
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
V-Ray for Revit Public API Client Reference Implementation
After you install V-Ray for Revit, you can find a reference implementation of a C# client at the following location: C:\Program Files\Chaos Group\V-Ray\V-Ray for Revit\PublicAPIClient.zip. Unzip the archive somewhere on your machine and explore the Visual Studio solution. Most of the code snippets above are taken directly from this sample application. The sample application is just a reference implementation and is provided as is.