Just updated the script with a user interface and some other options but im not getting the script to work........... some debugging required........ some help would be very much appreciated
(Global Material_Convertor
try(DestroyDialog Material_Convertor)catch()
local newmtl
local origMtl
local stMtl
local newmat
fn convert_Mtl_to_vray mtl =
(
if NOT isKindOf mtl Autodesk_Material then mtl
else case (mtl.DefinitionID as name) of
(
#Ceramic : vraymtl name:mtl.name Diffuse:mtl.Ceramic_Color Reflection:(color 200 200 200) reflection_glossiness: 0.85 reflection_subdivs: 16 reflection_fresnel: on reflection_lockIOR:off reflection_ior: 1.8
#Concrete : vraymtl name:mtl.name Diffuse:(color 120 120 120)
#Generic : vraymtl name:mtl.name Diffuse:mtl.Generic_Color
#Glazing : vraymtl name:mtl.name Diffuse:(color 0 0 0) reflection:(color 255 255 255) refraction:(color 255 255 255) reflection_fresnel: on refraction_ior: 1.52 refraction_fogColor: (color 234 252 247) refraction_fogMult: 5 option_traceReflection:on option_doubleSided:on option_reflectOnBack: on
#Hardwood : vraymtl name:mtl.name textmap_diffuse:mtl.wood_image
#MasonryCMU : vraymtl name:mtl.name Diffuse:mtl.Masonry_Color
#Metal : vraymtl name:mtl.name Diffuse:(color 156 156 156)
#MetallicPaint : vraymtl name:mtl.name Diffuse:mtl.Metallic_Paint_Color
#Mirror : vraymtl name:mtl.name Diffuse:mtl.Mirror_Tint_Color reflection:(color 255 255 255) refraction:(color 0 0 0) reflection_fresnel: on refraction_ior: 0.0 option_traceReflection:on option_doubleSided:on option_reflectOnBack: on
#PlasticVinyl : vraymtl name:mtl.name Diffuse:(color 177 177 177)
#Solidglass : vraymtl name:mtl.name Diffuse:(color 0 0 0) reflection:(color 255 255 255) refraction:(color 255 255 255) reflection_fresnel: on refraction_ior:mtl.Solid_Glass_Refraction refraction_fogColor: (color 234 252 247) refraction_fogMult: 5 option_traceReflection:on option_doubleSided:on option_reflectOnBack: on
#Stone : vraymtl name:mtl.name Diffuse:(color 120 120 120)
#WallPaint : vraymtl name:mtl.name Diffuse:mtl.Wall_Paint_Color
#water : vraymtl name:mtl.name Diffuse:(color 1 7 36) reflection:(color 255 255 255) refraction:(color 176 176 176) reflection_fresnel: on refraction_ior: 1.1
)
)
--Interface--
rollout Material_Convertor "--Autodsk Convtr--" width:120 height:170
(
label lbl_Name "Material Converter" pos:[5,2] width:127 height:17
GroupBox grp_convert "Convert to:" pos:[3,19] width:113 height:40
radiobuttons ToMaterialType "" pos:[25,33] width:77 height:64 labels:#("Vray") columns:1
GroupBox grp_SceneMat "Scene Materials:" pos:[3,60] width:113 height:67
radiobuttons ChangeWhat "" pos:[8,75] width:104 height:48 labels:#("Entire Scene", "Selected Objects", "Active Mat. Slot") columns:1
button Instancemat "Instance mats" pos:[3,130] width:113 height:16 toolTip:""
button convertScene "Convert" pos:[3,150] width:113 height:16 toolTip:""
on Instancemat pressed do
( --- instance materials with same name
objNamesArray = #()
objNodesArray = #()
ResultNames=#()
ResultNodes=#()
ResultCounts=#()
duplicateNames =#()
duplicateNodes=#()
scenenodes = scenematerials
for i = 1 to scenenodes.count do
(
if superclassof scenenodes[i] == material then
(
append objNamesArray scenenodes[i].name
append objNodesArray scenenodes[i]
)
)
n = objNamesArray.count
c=0
for i = 1 to n do
(
checkNum = finditem ResultNames objNamesArray[i]
if checknum == 0 then
(
c = c+1
ResultNames[c] = objNamesArray[i]
ResultNodes[c] = objNodesArray[i]
ResultCounts[c] = 1
)
else
(
ResultCounts[checkNum] = ResultCounts[checkNum] + 1
)
)
for d = 1 to ResultNames.count do
(
if ResultCounts[d] > 1 then
(
append duplicateNames ResultNames[d]
append duplicateNodes ResultNodes[d]
)
)
for h = 1 to duplicateNodes.count do
(
masternode = duplicateNodes[h]
for q = 1 to scenenodes.count do
(
if scenenodes[q].name == masternode.name then replaceInstances scenenodes[q] masternode
)
)
)
on convertScene pressed do
(
--Choose and create new Material
MaterialType = case ToMaterialType.state of
(
1: 1 -- Vray
)
case ChangeWhat.state of
(
--ENTIRESCENE:
1:
( if MaterialType == 1 then with redraw off
( if sceneMaterials.count == 0 do
return messageBox "There are no materials in your Scene!" title:"Autodsk Converter"
for mat in sceneMaterials do
replaceInstances mat (convert_Mtl_to_vray mat))
)
--SELECTEDOBJECTS:
2:
( if MaterialType == 1 then with redraw off
( for obj in selection where obj.material != undefined do
obj.material = convert_Mtl_to_Vray obj.material
)
)
--MATERIALEDITOR:
3:
(
if MaterialType == 1 then ----- Convert to Vray Material
(
origMtl = meditMaterials[medit.GetActiveMtlSlot()] -- get Active Material Slot
stMtl = convert_Mtl_to_Vray origMtl -- create a new VRay material out of this one
newmat = stMtl -- assing it to newmat
setMeditMaterial (medit.GetActiveMtlSlot()) newmat -- put the material to the new slot
)
)
)
)
)
Createdialog Material_Convertor style:#(#style_toolwindow, #style_border, #style_sysmenu)
)
--Createdialog Material_Convertor style:#(#style_toolwindow, #style_border, #style_sysmenu)
--clearListener()