Overview
Use these sample ready-to-use MaxScripts or snippets to automate common V-Ray tasks in 3ds Max, such as bulk editing lights, batch rendering .vrscene files, editing materials, and exporting proxies. Each section explains what the script does and provides the exact code to run.
Ready-to-use scripts
Add camera/custom metadata to .exr
Use this MAXScript to add EXR metadata (via VRayOptionRE) that holds camera and custom metadata.
Download the Add metadata to .exr MAXscript.
Mass material name editor
Use this MAXScript to edit all scene materials' names by adding prefix/suffixes or remove part of their symbols.
Download the Mass material name editor MAXscript.
Mass VRayLight Editor
Use this MAXScript to bulk edit all scene VRayLights' parameters.
Download the Mass VRayLight Editor MAXScript.
Mass VRayBitmap path editor
Use this MAXScript to mass edit (append prefix, suffix and replace strings) VRayBitmap paths.
Download the Mass VRayBitmap path editor MaxScript.
MultiTraceSets
Use this MAXScript to set the Reflection/Refraction Trace Sets for multiple objects.
Download the MultiTraceSets MaxScript.
Property Randomizer
Use this MAXScript to randomize different properties on the selected objects.
Download Property Randomizer MaxScript.
Save/Load VFB Region Presets
Use this MAXScript allows you to save VFB Region presets for later use. Note that only rectangular ones are supported.
Download the Save/Load VFB Region Presets MaxScript.
Snippets
Render all .vrscene files in a directory
Use this Windows batch script to render every .vrscene file in the current folder with V-Ray Standalone.
echo off
FOR %%I in (*.vrscene) DO (
FOR /F "tokens=1 delims=. " %%a in ("%%I") DO (
"C:\Program Files\Chaos\V-Ray\Standalone for x64\bin\vray.exe" -scenefile="%%I" -autoclose=1 -imgfile="%%a.jpg"
)
)
Note: -imgfile="%%a.jpg" attribute overrides the output file name and format. Use this
parameter only if output is not specified in *.vrscene files.
Change all VRayLightSelect render elements to Direct Diffuse
Run this MAXScript to set the mode of all VRayLightSelect render elements to Direct Diffuse.
MAXScript:
manager = maxOps.getCurRenderElementMgr()
numElements = manager.numrenderelements()
for n = 0 to (numElements-1) do
(
element = manager.getRenderElement n
if classof element == VRayLightSelect then
(
element.mode = 2
)
)
Select all VRayProxy objects using the same .vrmesh as the selected proxy
Run this MAXScript to select every VRayProxy in the scene that uses the same .vrmesh file as the currently selected proxy.
MAXScript:
if classof($) == VRayProxy then
(
searchFileName = $.fileName
)
else
(
print "Not a VRayProxy"
deselect $
)
for each in Objects do
(
if classof(each) == VRayProxy and each.fileName == searchFileName then
(
selectmore each
)
)
searchFileName = null
Lock reflection highlight glossiness of all VRayMtl nodes
Run this MAXScript to lock the Highlight Glossiness parameter on all VRayMtl materials.
MAXScript:
for each in SceneMaterials where classof each == VRayMtl do ( each.reflection_lockGlossiness = true )
Export a 3ds Max selection set to .vrmesh files
Use this MAXScript to export all objects from a named selection set (supports wildcards) to .vrmesh files.
MAXScript:
rollout ProxyExport "Proxy Export" width:300
(
label label1 "Enter Selection Set Name (wildcards * or partial-name):"
edittext setQuery
button createBtn "Create"
on createBtn pressed do
(
for i = 1 to getNumNamedSelSets() do
(
if matchPattern (getNamedSelSetName i) pattern:(setQuery.text) then select selectionSets[i]
)
vrayMeshExport meshFile: @"OUTPUT_FOLDER"
)
)
createDialog ProxyExportNote: Replace "OUTPUT_FOLDER" with the path where the the *.vrmesh files will be exported.
For example "C:\proxy-library\"
Change V-Ray object properties on selected objects
Run this MAXScript to set specific V-Ray Object Properties on the current selection.
MAXScript:
for each in Selection do
(
try(setUserProp each "VRay_GI_Generate" true)catch()
try(setUserProp each "VRay_GI_Receive" true)catch()
)Notes: The property names are written only if the V-Ray Objects Properties window has been opened at least once; V-Ray Object Property names can be found in: 3ds Max Object Properties > User Defined Tab.
Adjust 3ds Max Hair and Fur motion blur duration and interval
Run this MAXScript to find the 3ds Max Hair and Fur effect and set motion blur duration and interval type.
MAXScript:
TheEffects = (for i = 1 to numEffects where classof (getEffect i) == HairEffect collect (getEffect i)) theEffects[1].mbDuration = X theEffects[1].mbIntervalType = Y
Note: It is important to specify the X and Y values for the Duration and respectively, for the Interval Type.
Disconnect all VRayDirt maps
Run this MAXScript to find every VRayDirt map in the scene and disconnect it from its material.
MAXScript:
maps = getClassInstances VRayDirt asTrackViewPick:on
for map in maps do
for ref = 1 to refs.getNumRefs map.client where refs.getReference map.client ref == map.anim do
(
refs.replaceReference map.client ref undefined
notifyDependents map.client
)
Reset self-illumination on all assigned VRayMtl materials
Run this MAXScript to reset self-illumination parameters on all VRayMtl materials assigned to scene objects.
MAXScript:
for each in sceneMaterials do
(
if classOf each == VRayMtl then
(
each.selfIllumination = color 0 0 0;
each.selfIllumination_gi = false;
each.selfIllumination_multiplier = 1.0;
each.texmap_self_illumination = undefined;
each.texmap_self_illumination_on = true;
each.texmap_self_illumination_multiplier = 100.0;
each.compensate_camera_exposure = false;
)
)Note: This script works only with materials assigned in the scene.
Export selected objects and their materials to .vrmesh and .mat files
Run this MAXScript to export each selected object as a .vrmesh and save its material to a .mat file using the object’s name.
MAXScript:
function ExportProxyAndMatLib =
(
filesSavePath = getSavePath()
for eachObject in selection do
(
try
(
local matLib = MaterialLibrary()
append matLib eachObject.material
saveTempMaterialLibrary matLib (filesSavePath + "\\" + eachObject.name + ".mat")
vraymeshexport meshfile:(filesSavePath + "\\" + eachObject.name + ".vrmesh")
)
catch()
)
)
ExportProxyAndMatLib()Note: *.vrmesh and *.mat filenames are taken from object-name.
Select and delete the active camera
Run this MAXScript to select and delete the currently active camera.
MAXScript:
cam = getActiveCamera() select cam delete cam
Replace VRayFastSSS2 with VRayMtl while keeping outgoing connections
Run this MAXScript to replace all VRayFastSSS2 instances with default VRayMtl, preserving outgoing connections.
MAXScript:
for each in (getclassinstances VRayFastSSS2) do
replaceinstances each (VrayMtl())
Select objects by a custom user property value
Run this MAXScript to select all objects where a specified custom user property equals a specified value.
MAXScript:
for each in objects where (getuserprop each "my_property" == 2) do
(
selectmore each
)Note: Custom properties are defined from 3ds Max Objects Properties > User Defined rollout
Turn a selected object into a VRayClipper (Mesh mode with Replace Mesh on Pick)
Run this MAXScript to convert the selected object into a VRayClipper in Mesh mode, enable Replace Mesh on Pick, and hide the original mesh.
MAXScript:
clipMesh = $ clipper = VRayClipper() clipper.enable_mesh_mode = True clipper.mesh_replaceOnPick = True clipper.mesh_source = clipMesh clipper.pos = clipMesh.pos clipper.parent = clipMesh clipMesh.renderable = false hide clipMesh
Export each camera to a separate .vrscene file
Run this MAXScript to export each camera to its own .vrscene file. Animated cameras (position only) export from their first to last keyframe and use a separate output subfolder.
MAXScript:
fn ExportCamerasToVRScenes =
(
savePath = getSavePath()
for eachCam in Cameras where classof eachCam != Targetobject do
(
if savePath == undefined then continue
renderers.current.output_saveRawFile = true
renderers.current.output_rawFileName = savePath + "\Output\\" + eachCam.name + ".exr"
viewport.SetCamera eachCam
exportLocation = savePath + "\\" + eachCam.name
if eachCam.pos.isAnimated then
(
renderers.current.output_rawFileName = savePath + "\Output\\" + eachCam.name + "_Sequence\\" + eachCam.name + ".exr"
animRange = getTimeRange eachCam.position.controller #allKeys #children
animRangeStartFrame = (integer)animRange.Start
animRangeEndFrame = (integer)animRange.End
vrayExportVRScene exportLocation startFrame:animRangeStartFrame endFrame:animRangeEndFrame
)
else
(
vrayExportVRScene exportLocation
)
)
)
ExportCamerasToVRScenes()
Clean up leftover animation layers and MotionClips controllers
Run this MAXScript to remove leftover Animation Layer and MotionClips controllers. This helps scenes save/load faster and reduces file size.
MAXScript:
t=trackviewnodes n=t[#Anim_Layer_Control_Manager] deleteTrackViewController t n.controller gc() t=trackviewnodes n=t[#Max_MotionClip_Manager] deleteTrackViewController t n.controller gc()
Assign an existing material to the selection
Use this MaxScript to pick from materials assigned to geometry in the scene and apply one to the current selection.
MAXScript:
try(destroyDialog AssingExistingMat)catch()
rollout AssingExistingMat "Assign Existing Material"
(
listbox matListUI "Material List"
fn PopulateList =
(
for each in sceneMaterials do
(
appendString = each.name + " (" + (classof(each)as string) + ")"
matListUI.items = append matListUI.items appendString
)
)
on matListUI doubleClicked itm do
(
try
(
$.material = SceneMaterials[itm]
destroyDialog AssingExistingMat
)catch()
)
on AssingExistingMat open do
(
try (PopulateList())catch()
)
)
createDialog AssingExistingMatNote: Materials not assigned to any geometry are not listed.
Print all property–value pairs of the selected object’s material
Run this MAXScript to output all property names and their values for the currently selected object’s material.
MAXScript:
for p in getPropNames $.material do format "% = %\n" p (getProperty $.material p)
Toggle a Physical/V-Ray camera’s cone on or off
Run this MAXScript to toggle the visibility of the selected Physical or V-Ray camera’s cone.
MAXScript:
for p in getPropNames $.material do format "% = %\n" p (getProperty $.material p)
Create a custom V-Ray raw image save file dialog
Use this MaxScript to configure V-Ray raw image output (file path, EXR/VRST options, deep EXR, frame numbering, and VFB color corrections).
MAXScript:
try(destroyDialog saveRollout)catch()
rollout setRawFile "Save Raw file"
(
edittext pathText
button browseButton "Browse"
checkbox useHalf "EXR/VRST 32-bit output"
checkbox useDeep "Deep EXR"
checkbox useDots "Dot-deliminated frame number"
checkbox useCorr "Save VFB color corrections to RGB channel"
on setRawFile open do
(
renderers.current.output_saveRawFile=true
useHalf.checked = not renderers.current.output_rawExrUseHalf
useDeep.checked = renderers.current.output_rawExrDeep
useDots.checked = renderers.current.fileName_addDot
useCorr.checked = renderers.current.output_rawSaveColorCorrections
pathText.Text = renderers.current.output_rawFileName
)
on useHalf changed current_state do renderers.current.output_rawExrUseHalf = not current_state
on useDeep changed current_state do renderers.current.output_rawExrDeep = current_state
on useDots changed current_state do renderers.current.fileName_addDot = current_state
on useCorr changed current_state do renderers.current.output_rawSaveColorCorrections = current_state
on browseButton pressed do
(
try
(
renderers.current.output_rawFileName = getSaveFileName types:"V-Ray image files(*.vrimg)|*.vrimg|OpenEXR image files(*.exr)|*.exr|V-Ray deep image files(*.vrst)|*.vrst|"
pathText.Text = renderers.current.output_rawFileName
)catch()
)
)
CreateDialog setRawFile 500 150
Render a custom frame range and save only the effectsResult channel
Run this MAXScript to render a frame range and save only the effectsResult channel from the VFB to disk.
MAXScript:
fn SaveEffectsResultOnly =
(
startFrame = 0
endFrame = 50
for i = startFrame to endFrame do
(
slidertime = i
max quick render
outputImg = @"D:\" + i as string + ".exr"
vfbControl #setchannel (vfbControl #getchannel effectsresult)[1]
vfbControl #saveimage outputImg
)
)
try(SaveEffectsResultOnly())catch()Note: Control the range with startFrame and endFrame. Set the output path via outputImg.
Load a LUT file into V-Ray VFB for color transformations
Run this MAXScript to create a LUT layer in the V-Ray VFB and load a .cube LUT file.
MAXScript:
vfbLayers= (vfbcontrol #getlayermgr)[1]
vfbLayers.createLayer 1 "chaos.cc.lut"
for each in vfbLayers.getAllLayerIds() do
(
try
(
(vfbLayers.getLayer each).lut_file = @"X:\CC_file.cube"
)
catch()
)Note: Replace the file path with your own.