macroScript VrmeshConverter category:"cooper" ( rollout VrayMesh "Vray mesh converter" ( Group "Settings" ( button browse "vrmesh folder" width:180 height:30 edittext saveto "" width:180 height:20 enabled:false checkbox savemesh "save selected as .max" dropdownlist polys "faces in preview" items:#("100","1000", "5000", "10000" ) selection:3 button apply "Export to vrmesh" ) on browse pressed do ( try (global vrmesh_path= (getSavePath caption:"my title")+ "\\Vrmesh") catch() saveto.text = vrmesh_path renderSceneDialog.update() ) on apply pressed do ( undo on ( disablesceneredraw() max create mode vrmeshPath = vrmesh_path makeDir vrmeshPath previewFaces = polys.text as number origObjArray = #() convertedObjArray = #() InstArray = #() uniqueObjects = #() selectedObjects = selection as array for i in selectedObjects where superclassof i == geometryclass do ( if finditem InstArray i == 0 then ( InstanceMgr.GetInstances i &Instances InstArray = InstArray + Instances append uniqueObjects i ) ) for g in uniqueObjects do if isgrouphead g do setGroupOpen g true ObjCount = uniqueObjects.count max select none progressStart ("Converting " + ObjCount as string + " objects") iter = 0 for i in uniqueObjects do ( undo off ( iter = iter + 1 -- i = selection[1] origObj = i if classof origObj != Vrayproxy then ( if getUserProp origObj "VrmeshPath" == undefined then ( vrmeshName = vrmeshPath + "\\" + origObj.name + ".vrmesh" originalName = vrmeshPath + "\\" + origObj.name + ".max" if savemesh.state == true do ( saveNodes origObj (vrmeshPath + "\\" + origObj.name + ".max") ) InstanceMgr.GetInstances origObj &TempInst for g in TempInst do setUserProp g "VrmeshPath" vrmeshName for g in TempInst do setUserProp g "OriginalPath" originalName select origObj vraymeshexport meshFile: vrmeshName display:0 maxPreviewFaces:previewFaces convertedObj = VRayProxy filename: vrmeshName ) else ( vrmeshName = getUserProp origObj "VrmeshPath" convertedObj = VRayProxy filename: vrmeshName ) append origObjArray origObj append convertedObjArray convertedObj ) else ( revertname = getFilenameFile i.filename mergemaxfile (vrmeshPath + "\\" + revertname + ".max") #(revertname) #select #noRedraw #mergeDups #useSceneMtlDups #neverReparent append origObjArray origObj append convertedObjArray selection[1] ) ) progressUpdate (100 * iter / (ObjCount + 1) ) ) for q = 1 to origObjArray.count do instancereplace origObjArray[q] convertedObjArray[q] for f in convertedObjArray do delete f for g in uniqueObjects do if isgrouphead g do setGroupOpen g false select selectedObjects progressEnd() enablesceneredraw() completeredraw() gc() ) ) ) ( Createdialog Vraymesh 200 200 ) )