This page provides information on using MAXScript with V-Ray.

 

Page Contents ×

Overview


In 3ds Max, assuming that your current renderer is set to V-Ray, you can refer to it from MAXScript using the renderers structure:

vr=renderers.current

V_Ray_Next__1:V_Ray_Next__1


Renderer Properties


Assuming that the variable vr holds an instance of the V-Ray renderer, you can work with the renderer settings as with any other MAXScript object:

showproperties vr

 .imageSampler_type : integer

.fixedRate_subdivs : integer

.fixedRate_rand : boolean

...............

...............

...............

.options_maxDepth : integer

.options_maps : boolean

.options_filterMaps : boolean

.output_on : boolean

.output_width : integer

.output_height : integer

.output_fileOnly : boolean

.output_saveFile : boolean

.output_fileName : string

.output_saveRawFile : boolean

.output_rawFileName : string

false


Accessing the parameters is fairly easy, for example:

vr.gi_on=true
true

 

Renderer Methods  


The following methods can be used for saving/loading irradiance and photon maps (assuming that vr holds an instance of V-Ray):

Renderer method Description
vr.saveIrradianceMap <filename> Saves the current irradiance map to the given file.
vr.saveLightCache <filename> Saves the current light cache to the given file.
vr.loadIrradianceMap <filename> Loads the irradiance map from the given file.
vr.clearIrradianceMap()clears the irradiance map that is currently in memory
vr.clearLightCache()Clears the light cache that is currently in memory.
vr.showLastVFB()Shows the V-Ray VFB window with last rendered image.

 

Global Functions


Additionally, the following MAXScript functions are globally available:

Global function Description
doVRayObjectProperties()Brings up the V-Ray Object Properties dialogue.
doVRayMeshExport()Brings up the V-Ray Mesh Export dialogue.

vrayMeshExport 

[meshFile:"<mesh file>"]

 

[autoCreateProxies:true|false]

[exportMultiple:true|false]

[animation:on|off]

[animationRange:#scene|#explicit]

[animationStart: <integer>]

[animationEnd: <integer>]

[animationRedrawViews:true|false]

[minPreviewFaces: <integer>]

[maxPreviewFaces: <integer>]

[previewFacesPercentage:<integer>]

[previewMesh: <preview node>]

[nodes:<object/array of objects/ objectset>]

[proxyName:"<string>"]

[createMultiMtl:true|false]

[condenseMultiMtl:true|false]

[facesPerVoxel: <integer>]

[oneVoxelPerMesh:true|false]

[exportPointClouds:true|false]

[pointSize:<float>]

[previewType:<string>]

 

Exports a .vrmesh file without showing a dialog. Returns an array of newly created VRayProxy object(s), if any.

<mesh file>  is the name of the desired  .vrmesh  file. If the name does not contain a path, the default 3ds Max mesh path is used. If the name does not contain an extension, a  .vrmesh  extension is automatically appended. If the name does not contain a file name, the scene node name is used instead.

If the  autoCreateProxies  option is not specified, by default the meshes are just exported, no proxies are created in the scene.

If the  exportMultiple  option is not specified, the meshes are exported to multiple files by default.

If the  animation  option is set to  on , an animated proxy file is created.

In that case, the range of the animation is determined by the  animationRange  option - if set to  #explicit , then the frame range for the export is specified by the  animationStart  and  animationEnd  options (in frames), otherwise the current scene animation range is used.


If the  animationRedrawViews  option is set to  true  then the viewports will be updated during the animation export process.

If the minPreviewFaces  parameter is specified, then the exported  .vrmesh  file will contain a preview with the specified minimum number of triangles .

If the maxPreviewFaces  parameter is specified, then the exported  .vrmesh  file will contain a preview with the specified maximum of triangles, otherwise a default value of  10000  triangles is used.

If the previewFacesPercentage parameter is specified, then that percentage of the total faces are shown in the preview mesh.


previewType can accept three strings as values: "clustering" , "combined" and "face_sampling" (which in that order correspond to "Vertex clustering", "Refined clustering" and "Face skipping" from the UI)

 Note: The previewMesh option is only valid when exporting to a single .vrmesh file (i.e. exportMultiple is  false) . The proxyName option is only valid when autoCreateProxies is true.

vrayMeshImport 

[proxy: <proxy mesh object(s)>]

[explicitNormals: true|false]

[weldVertices: true|false]

Imports the geometry of the selected VRayProxy object(s) as an editable mesh

<proxy mesh object(s)> is a single  VRayProxy  object, an array of  VRayProxy  objects or an ObjectSet  (for example $geometry) . If this option is not specified  VRayProxy  object(s) from the current selection are imported as mesh(es).

registerVRayMenus()Registers the various V-Ray components (lights, cameras, geometry objects, modifiers etc) into the 3ds Max Create, Modifiers etc. menus. This function is useful if the 3ds Max menu system is reset and the menu associations are lost. You can also call this function directly from the V-Ray toolbar.
unregisterVRayMenus()Removes V-Ray specific items from the 3dsMax standard menus
updateVRayMenus()Refreshes all V-Ray specific items in the 3ds Max standard menus
setVRaySilentMode()Disables any V-Ray dialogues that may appear when loading a scene (i.e. notification for differences with older versions, etc.).
vrayEditDRSettings()Opens the dialogue for editing the V-Ray DR settings.
vrayAddTraceSets <node> Adds and returns a new V-Ray trace sets object for the specified node (or just returns it, if there is one already). Use showproperties on the returned object to see what properties are available (the reflection and refraction trace sets).
vrayRemoveTraceSets <node> Removes the V-Ray trace sets object for the specified node.
vrayGetTraceSets <node> Returns the V-Ray trace sets object for the specified node, or undefined if there isn't one.
vrayVersion()Returns an array of two elements with the current version of V-Ray and the build number. The build number is only defined for nightly builds and may be an empty string for official builds.
vrayShowMsgLogWindow()Shows the V-Ray messages window.
vrayCloseMsgLogWindow()Closes the V-Ray messages window.
vrayUpdateCRTEnvVars()Updates the CRT environment variables. This function can be called to update the environment after setting or changing environment variables.

V-Ray VFB Functions


The following global MAXScript functions are available for access to the V-Ray virtual frame buffer.

Global VFB function Description
vrayVFBGetRegionEnabled()Returns whether region rendering in the V-Ray VFB is enabled (true) or disabled (false).
vrayVFBGetRegion()Returns an array with four integer elements, representing the pixel coordinates of the VFB render region (left, top, right, bottom). The left and top coordinates are included in the region, the right and bottom one are not.

vrayVFBSetRegionEnabled true|false

Turns on or off the VFB region render option.

vrayVFBSetRegion left top right bottomSets the VFB render region to the specified
coordinates.
vrayVFBGetNumChannels()Returns the number of channels (render elements) in the V-Ray VFB. This will return 0 if the VFB is not initialized or does not store any data.
vrayVFBGetChannelName iReturn the name of the i-th channel. Indexes start from 1.
vrayVFBGetChannelType iReturns the storage type of the i-th channel. Indexes start from 1. The return value specifies the type of data for each pixel in the given channel:
0 - the index is not valid or the VFB does not store an image;
1 - a single floating-point number (this is used, for example, for the z-depth channels);
2 - three floating-point numbers (this is used for regular color channels);
3 - two floating-point numbers;
4 - a single integer number (used, for example, by the render ID and material ID elements);
5 - three signed floating-point numbers (this is used, for example, for normals and world position channels).
vrayVFBGetChannelAlias iReturns the alias for the i-th channel. Indexes start from 1. See the RegionChannelAlias enum in the file "pixelbuffer.h" from the V-Ray SDK.
vrayVFBGetChannelBitmap iReturns the contents of the specified channel as a 3ds Max bitmap. Indexes start from 1. This will return undefined if the channel index is not valid or the VFB does not contain any data.
vfbControl()Allows control over the various aspects of the V-Ray VFB. Type vfbControl() for a list of available parameters, or for more details see the Controlling the VFB Programmatically page.
vfbControl #show [true/false]Opens (true) or Closes (false) the VFB window or returns its current display state if called without a value.

 

V-Ray GPU Functions


Additional MAXScript functions are added by the V-Ray GPU renderer.

V-Ray GPU functionDescription
vrayGetRTBitmap()Returns the contents of current ActiveShade window as a bitmap, or undefined if ActiveShade is not started.

vrayExportVRScene <filename>

[separateFiles: true|false]

[exportView: true|false]

[exportLights: true|false]

[exportGeometry: true|false]

[exportNodes: true|false]

[exportMaterials: true|false]

[exportTextures: true|false]

[exportBitmaps: true|false]

[incrBaseFrame: true|false]

[prefix: <prefix string>]

[startFrame: <startFrame>]

[endFrame: <endFrame>]

[stripPaths: true|false]

Directly export the current 3ds Max scene into a .vrscene file from the current viewport. If the separateFiles option is set to true, the scene components will be split in different files depending on their type (view transformation, lights, mesh geometry, node transformations, materials, textures and bitmaps). If the prefix keyword is specified, the prefix string will be added in front of all plugin names in the resulting .vrscene file. If the startFrame and endFrame options are specified, an animated .vrscene file is exported for the specified frames. If the stripPaths option is set to true, then any assets (bitmaps, irradiance maps, IES files etc) are only written with their file names, without the path.

NOTE: The exporter takes the render settings from V-Ray GPU, thus it must be the current production renderer, otherwise default rendering settings will be exported.

NOTE 2: Currently the .vrscene export follows the settings in the V-Ray GPU renderer for export of proxies, X-Ref scenes and containers, particle systems and displacement.

With V-Ray Next GPU selected as production renderer all script specific to this engine can be listed by executing:

vr = renderers.current

V_Ray_GPU_Next__update_1_1:V_Ray_GPU_Next__update_1_1

showproperties vr

Some of the settings reside under V_Ray_settings. In order to list those properties you can use the following commands:

showproperties vr.V_Ray_settings.

 

V-Ray IPR Functions


Additional MAXScript functions are available for Interactive Production Rendering.

V-Ray IPR functionDescription
vrayIsRenderingIPR()Returns true if an IPR render is active and false if not.
vrayStartIPR()Starts interactive production rendering for the production renderer either V-Ray or V-Ray GPU.
vrayUpdateIPR()Refreshes interactive rendering.

vrayStopIPR()

Stops the current interactive rendering.

Image Completed Callback

When the rendering is complete, V-Ray will try to call a MAXScript function called vrayIPRImageComplete. To perform an action when the rendering is finished, you can define this function yourself. For example, the following code prints a message when the rendering is complete:

global vrayIPRImageComplete

fn vrayIPRImageComplete = (
		print "IPR Image completed "
)