This page provides information about V-Ray for Revit Public APIs.
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.
V-Ray for Revit Public API provides the
|
|
|
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); } |
|
|
|
GetProjectNameRequest
message GetProjectNameRequest { google.protobuf.Empty empty = 1; } |
GetProjectNameRequest
has no properties.
GetProjectNameResponse
|
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.
|
|
|
GetProjectChangedNotificationStreamRequest
|
GetProjectChangedNotificationStreamRequest
has no properties.
ProjectChangedNotification
|
project_name
: A string containing the name of the project that is currently active in Revit.
|
|
|
GetViewsRequest
|
GetViewsRequest
has no properties.
GetViewsResponse
|
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
|
ViewMap
|
values:
A map containing all views, where the key is the unique id of the
|
|
View
|
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.
|
|
SelectViewResponse |
SelectViewRequest
|
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
|
SelectViewResponse
|
success_status:
A boolean indicating whether the RPC succeeded.message:
A string containing an error message in case the RPC failed for some reason.
|
|
|
|
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.
|
success_status:
A boolean indicating whether the RPC succeeded.message:
A string containing an error message in case the RPC failed for some reason.
|
|
|
GetPropertiesRequest
|
GetPropertiesRequest
has no properties.
GetPropertiesResponse
|
property_map: A
|
PropertyMap
|
values
: A map containing all properties, where the key is the unique name of the Property, and the value is the Property itself.
Property
|
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
|
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.
PropertyValue
|
value:
Contains oneof the possible values for a property depending on its type.
|
|
|
GetPropertyRequest
message GetPropertyRequest { string unique_name = 1; } |
unique_name:
A string that contains the unique name of the property.
GetPropertyResponse
|
|
|
|
SetPropertyRequest
|
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
|
success_status:
A boolean indicating whether the RPC succeeded.message:
A string containing an error message in case the RPC failed for some reason.
|
|
|
ExportVRSceneRequest
|
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
|
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.
|
|
|
GetVRayMaterialsRequest
|
GetVRayMaterialsRequest
has no properties.
GetVRayMaterialsResponse
bool success_status = 1; } |
|
|
|
|
|
SaveVRayMaterialToFileRequest
|
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
bool success_status = 1;
|
success_status:
A boolean indicating whether the RPC succeeded.message:
If the RPC failed, this would be a string containing an error message.
LightingAnalysisQuantity
|
LuminanceCD:
Uses the Illuminance of the rendered frame in lux.IlluminanceLX:
Uses the Luminance of the rendered frame in candelas.LightingAnalysisScale
|
Linear:
The colors are mapped in linear scale.Logarithmic:
The colors are mapped in logarithmic scale.
LightingAnalysisDisplay
|
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
|
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
|
Default:
Default V-Ray DenoiserNVIDIA:
NVidia Al Denoiser
DenoiserRadiusType
|
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
|
CPU:
CPUGPU:
CUDA(GPU)RTX:
RTX(GPU)
VRayResolutionRatio
|
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
|
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
|
Inches:
InchesMillimeters:
Millimeters
EnvironmentType
Sun = 0;
|
Sun:
V-Ray SunDome:
V-Ray Dome LightNone:
No V-Ray Lights
ScreenPlacementType
ScreenPlacement = 0;
|
ScreenPlacement:
Screen PlacementSphericalPlacement:
SphericalPlacement
BackgroundType
NoBackground = 0;
|
NoBackground:
No BackgroundCustomBackground:
Custom BackgroundRevitBackground:
Revit Background
VRaySceneQuality
Draft = 0;
|
Draft:
Draft QualityLow:
Low QualityMedium:
Medium QualityHigh:
High QualityVeryHigh:
VeryHigh Quality
VRayImageSamplerType
UnusedVRayImageSamplerType = 0;
|
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
IrradianceMap = 0;
|
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
Full = 0;
|
Full:
Full light evaluation.Adaptive:
Optimizes the sampling of lights in scenes with many lights.
VRayCameraMode
Standard = 0;
|
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
UnusedVRayCameraStereoLayout = 0;
|
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
FixedDistance = 0;
|
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.
FamilyType = 0;
|
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.
Preetham = 0;
|
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)
Pixels = 0;
|
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
float r = 1;
|
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
float r = 1;
|
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.
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 |
|
Here is how the
|
"apiServers": [ { "PID": 22920, }, "PID": 14792, } ] |
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; $"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; JObject apiServer; apiServer = apiServers.OfType<JObject>().SingleOrDefault(jo => (int)jo["PID"] == Process.GetCurrentProcess().Id); } 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
|
Note that the code above uses the Newtonsoft Json.NET library, but you can read the json file in any way that you prefer.
public async Task<bool> ConnectAsync() { var serverPort = GetServerPort(); this.channel = new Channel($"localhost:{serverPort}", ChannelCredentials.Insecure); var deadline = DateTime.UtcNow.AddSeconds(1); await this.channel.ConnectAsync(deadline); return true; } return false; } } Debug.WriteLine("Public API Server has not started yet!"); } } |
|
public async Task<string> GetProjectNameAsync() try var client = new ApiServerClient(this.channel); return response.ProjectName; } MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } Debug.WriteLine(e); } } |
|
GetProjectNameRequest |
|
public async Task<IEnumerable<View>> GetViewsAsync() try var client = new ApiServerClient(this.channel); return response.ViewMap.Values.Values; } MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } Debug.WriteLine(e); } } |
|
|
|
public async Task<bool> SelectViewAsync(string uniqueId) try var client = new ApiServerClient(this.channel); return true; } MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } Debug.WriteLine(e); } } |
|
public async Task<bool> SetBatchRenderViewAsync(string uniqueId, bool batchRender) try var client = new ApiServerClient(this.channel); return true; } MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error) } } Debug.WriteLine(e); } } |
|
|
public async Task<IEnumerable<Property>> GetPropertiesAsync() try var client = new ApiServerClient(this.channel); return response.PropertyMap.Values.Values; } MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } Debug.WriteLine(e); } } |
|
|
|
public async Task<Property> GetPropertyAsync(string uniqueName) try var client = new ApiServerClient(this.channel); return response.Property; } MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } Debug.WriteLine(e); } } |
|
public async Task<bool> SetPropertyAsync(string uniqueName, PropertyValue propertyValue) try var client = new ApiServerClient(this.channel); UniqueName = uniqueName, }; return true; } MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } Debug.WriteLine(e); } } |
|
|
|
|
|
|
|
|
|
|
|
public async Task<Tuple<bool, string>> ExportVRSceneAsync(string exportFilePath, bool exportAsArchive, bool exportCompressed, bool exportHexFormat) { try var client = new ApiServerClient(this.channel); var response = await client.ExportVRSceneAsync(new ExportVRSceneRequest() ExportFilePath = exportFilePath, }); // If the export was successfull, response.Message will contain the } Debug.WriteLine(e); } } Debug.WriteLine(e); } } |
|
|
|
public async Task<IEnumerable<string>> GetVRayMaterialsAsync() try var client = new ApiServerClient(this.channel); var response = await client.GetVRayMaterialsAsync(new GetVRayMaterialsRequest()); return response.MaterialNames; } MessageBox.Show(response.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } Debug.WriteLine(e); } } |
|
|
|
public async Task<Tuple<bool, string>> SaveVRayMaterialToFileAsync(string materialName, string filePath) { try var client = new ApiServerClient(this.channel); var response = await client.SaveVRayMaterialToFileAsync(new SaveVRayMaterialToFileRequest() MaterialName = materialName, }); return new Tuple<bool, string>(response.SuccessStatus, response.Message); } Debug.WriteLine(e); } } Debug.WriteLine(e); } } |
|
|
|
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(e); } } |
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.
|