Converting Autodesk materials

Converting Autodesk materials

hanselmoniz
Enthusiast Enthusiast
10,435 Views
52 Replies
Message 1 of 53

Converting Autodesk materials

hanselmoniz
Enthusiast
Enthusiast
Please could you help out to change autodesk materials to vray materials. So far I've got. I would however have to grab the properties of individual autodesk materials and set them to vray... i do not know if I'm going in the right direction as i am new to maxscript


for varMat in scenematerials do
( if classof varMat == Autodesk_Material then
if varMat = Autodesk_ceramic then
(varMat = vraymtl ())
if varMat = Autodesk_concrete then
(varMat = vraymtl ())
if varMat = Autodesk_generic then
(varMat = vraymtl ())
if varMat = Autodesk_glazing then
(varMat = vraymtl ())
if varMat = Autodesk_wood then
(varMat = vraymtl ())
if varMat = Autodesk_masonry then
(varMat = vraymtl ())
if varMat = Autodesk_metal then
(varMat = vraymtl ())
if varMat = Autodesk_metallic_paint then
(varMat = vraymtl ())
if varMat = Autodesk_mirror then
(varMat = vraymtl ())
if varMat = Autodesk_plastic then
(varMat = vraymtl ())
if varMat = Autodesk_solid_glass then
(varMat = vraymtl ())
if varMat = Autodesk_stone then
(varMat = vraymtl ())
if varMat = Autodesk_wall_paint then
(varMat = vraymtl ())
if varMat = Autodesk_water then
( varMat = vraymtl ())

)
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
10,436 Views
52 Replies
Replies (52)
Message 21 of 53

Swordslayer
Advisor
Advisor
Case expression is your friend:

fn convert_Mtl_to_mrArchitectural mtl =
(
if NOT isKindOf mtl Autodesk_Material then mtl
else case (mtl.DefinitionID as name) of
(
#Ceramic : Arch___Design__mi diffuse:mtl.Ceramic_Color diff_color_map:mtl.Ceramic_Color_Map /*...*/
#Concrete : ()
#Generic : ()
#Glazing : ()
#Hardwood : ()
#Masonry_CMU : ()
#Metal : ()
#MetallicPaint : ()
#Mirror : ()
#Plastic_Vinyl : ()
#Solid_glass : ()
#Stone : ()
#Wall_paint : ()
#water : ()
)
)


However, my preference would still be to use the ConvertToGeneric method.
0 Likes
Message 22 of 53

hanselmoniz
Enthusiast
Enthusiast
The problem is that i do not have a copy of 3dsmaxdesign 2013 im still using the 2011 version so the ConvertToGeneric method is absent...
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 23 of 53

Swordslayer
Advisor
Advisor
Okay, in that case this is the next best solution. For all the other case branches I didn't fill in, pass the keyword parameters to the Arch___Design__mi constructor just the same way as in the #Ceramic branch.
0 Likes
Message 24 of 53

hanselmoniz
Enthusiast
Enthusiast
I have got this so far just basic changes from autodesk to vray materials but masonry_CMU, Plastic_vinyl Solid_glass and Wall_paint do not get converted do not know why? It just says cannot assign undefined to material Editor Slots could this be because of the Underscore as name
fn convert_Mtl_to_vray mtl =
(
if NOT isKindOf mtl Autodesk_Material then mtl
else case (mtl.DefinitionID as name) of
(
#Ceramic : vraymtl Diffuse:(color 200 200 200) Reflection:(color 200 200 200) reflection_glossiness: 0.85 reflection_subdivs: 16 reflection_fresnel: on reflection_lockIOR:off reflection_ior: 1.8
#Concrete : vraymtl Diffuse:mtl.Concrete_Color
#Generic : vraymtl Diffuse:mtl.Generic_Color
#Glazing : vraymtl 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 textmap_diffuse:mtl.wood_image
#Masonry_CMU : vraymtl Diffuse:mtl.Masonry_Color
#Metal : vraymtl Diffuse:(color 156 156 156)
#MetallicPaint : vraymtl Diffuse:mtl.Metallic_Paint_Color
#Mirror : vraymtl Diffuse:mtl.Mirror_Tint_Color
#Plastic_Vinyl : vraymtl Diffuse:(color 177 177 177)
#Solid_glass : vraymtl 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
#Stone : vraymtl textmap_diffuse:mtl.Stone_Image
#Wall_Paint : vraymtl Diffuse:mtl.Wall_Paint_Color
#water : vraymtl Diffuse:(color 177 211 173) reflection:(color 255 255 255) refraction:(color 255 255 255) reflection_fresnel: on refraction_ior: 1.1
)
)


origMtl = meditMaterials -- get Active Material Slot
stMtl = convert_Mtl_to_vray origMtl -- create a new Autodesk material out of this one
stMtl.name = origMtl.name
newmat = stMtl -- assing it to newmat
newmat.name=stMtl.name
setMeditMaterial (medit.GetActiveMtlSlot()) newmat -- put the material to the new slot
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 26 of 53

hanselmoniz
Enthusiast
Enthusiast
thanks very much appreciated...
fn convert_Mtl_to_vray mtl =
(
if NOT isKindOf mtl Autodesk_Material then mtl
else case (mtl.DefinitionID as name) of
(
#Ceramic : vraymtl 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 Diffuse:mtl.Concrete_Color
#Generic : vraymtl Diffuse:mtl.Generic_Color
#Glazing : vraymtl 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 textmap_diffuse:mtl.wood_image
#MasonryCMU : vraymtl Diffuse:mtl.Masonry_Color
#Metal : vraymtl Diffuse:(color 156 156 156)
#MetallicPaint : vraymtl Diffuse:mtl.Metallic_Paint_Color
#Mirror : vraymtl Diffuse:mtl.Mirror_Tint_Color
#PlasticVinyl : vraymtl Diffuse:(color 177 177 177)
#Solidglass : vraymtl 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 textmap_diffuse:mtl.Stone_Image
#WallPaint : vraymtl Diffuse:mtl.Wall_Paint_Color
#water : vraymtl Diffuse:(color 177 211 173) reflection:(color 255 255 255) refraction:(color 255 255 255) reflection_fresnel: on refraction_ior: 1.1
)
)

origMtl = meditMaterials -- get Active Material Slot
stMtl = convert_Mtl_to_vray origMtl -- create a new Autodesk material out of this one
stMtl.name = origMtl.name
newmat = stMtl -- assign it to newmat
newmat.name=stMtl.name
setMeditMaterial (medit.GetActiveMtlSlot()) newmat -- put the material to the new slot
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 27 of 53

Swordslayer
Advisor
Advisor
Btw. you can pass the material name to the constructor as well, .. vraymtl name:mtl.name .. Makes it a bit more comfortable using the function.
0 Likes
Message 28 of 53

hanselmoniz
Enthusiast
Enthusiast
will this code extract the autodesk_bitmap filepath value
 if hasProperty varMat "Generic_Image" then
(
if classof varMat.Generic_Image == Autodesk_Map then
(
varGenericTextureName = varMat.Generic_Image.Parameters_Source)
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 29 of 53

Swordslayer
Advisor
Advisor
I think you want isProperty, not hasProperty. Also instead of having nested if expressions you can chain them with and, as in most languages it is sort-circuiting operator in MAXScript, too, which means it won't evaluate the next condition if the previous one is false:

if isProperty varMat "Generic_Image" AND classof varMat.Generic_Image == Autodesk_Map then
varGenericTextureName = varMat.Generic_Image.Parameters_Source
0 Likes
Message 30 of 53

hanselmoniz
Enthusiast
Enthusiast
This works only with materials in the material editor... Do not know where im going wrong
any help will be much appreciated
--Variables--
(Global Material_Convertor
try(DestroyDialog Material_Convertor)catch()
local newmtl

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:mtl.Concrete_Color
#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 textmap_diffuse:mtl.Stone_Image
#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:165
(
label lbl_Name "Material Converter" pos: width:127 height:17
GroupBox grp_convert "Convert to:" pos: width:113 height:40
radiobuttons ToMaterialType "" pos: width:77 height:64 labels:#("Vray") columns:1
GroupBox grp_SceneMat "Scene Materials:" pos: width:113 height:67
radiobuttons ChangeWhat "" pos: width:104 height:48 labels:#("Entire Scene", "Selected Objects", "Active Mat. Slot") columns:1
button convertScene "Convert" pos: width:113 height:16 toolTip:""
progressBar convert_prog "" pos: width:113 height:6 color:(color 243 103 0)




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 ----- Convert to Vray Material
(
disableSceneRedraw()
orgSceneMaterials = sceneMaterials
numOfMatInScene = orgSceneMaterials.count
if (numOfMatInScene == 0) do
(
MessageBox "There are no materials in your Scene!" title:"Autodsk Converter"
)

for i = 1 to numOfMatInScene do
(
local u
convert_Mtl_to_Vray orgSceneMaterials

NumOfObjects = objects.count
for u = 1 to NumOfObjects do
(
if ( objects.material == orgSceneMaterials ) do
(
objects.material = newmtl
)
)
)

enableSceneRedraw()
completeredraw()
)
)

--SELECTEDOBJECTS:
2:
(
if MaterialType == 1 then ----- Convert to Vray Material
(
disableSceneRedraw()
tempSel = getCurrentSelection()
for i = 1 to tempSel.count do
(
if tempSel.material != undefined then
(
convert_Mtl_to_Vray tempSel.material
enableSceneRedraw()
completeredraw()

)
)
)
)


--MATERIALEDITOR:
3:
(
if MaterialType == 1 then ----- Convert to Vray Material
(
origMtl = meditMaterials -- 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()

`
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 31 of 53

Swordslayer
Advisor
Advisor
You are creating the material and throwing it away instantly. Use the result of conversion - and btw. there's no need to reassign the materials when using replaceInstances.

 --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
)
)
0 Likes
Message 32 of 53

hanselmoniz
Enthusiast
Enthusiast
thanks will try this out
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 33 of 53

Anonymous
Not applicable

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()

	

 

0 Likes
Message 34 of 53

Swordslayer
Advisor
Advisor

What exactly doesn't work as expected? I just tested it very briefly and it seems to work without glitches, althought the code (especially the formatting) could be cleaned up a bit:

 

(
    try (destroyDialog ::Material_Convertor) catch()

    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:""

        -- toMaterialType enum
        local VRAY_MAT = 1

        -- changeWhat enum
        local ENTIRE_SCENE = 1
        local SELECTED_OBJECTS = 2
        local ACTIVE_SLOT = 3

        on instanceMat pressed do
        ( --- instance materials with same name
            local checkedMats = #()
            local checkedMatNames = #()
            local counter = 0

            for mat in sceneMaterials
                where isKindOf mat Material do
                (
                    local checkNum = findItem checkedMatNames mat.name
                    if checkNum > 0 then
                        append checkedMats[checkNum] mat
                    else
                    (
                        append checkedMatNames mat.name
                        append checkedMats #(mat)
                    )
                )

            for mats in checkedMats
                where mats.count > 1 do
                    for i = 2 to mats.count do
                        replaceInstances mats[i] mats[1]
        )

        on convertScene pressed do
        (
            case ChangeWhat.state of
            (
                ENTIRE_SCENE :
                (
                    if sceneMaterials.count == 0 do
                        return messageBox "There are no materials in your Scene!" title:"Autodsk Converter"

                    if ToMaterialType.state == VRAY_MAT then with redraw off
                        for mat in sceneMaterials do
                            replaceInstances mat (convert_Mtl_to_vray mat)
                )
                SELECTED_OBJECTS :
                (
                    if ToMaterialType.state == VRAY_MAT then with redraw off
                        for obj in selection where obj.material != undefined do
                            obj.material = convert_Mtl_to_Vray obj.material  
                )
                ACTIVE_SLOT : 
                (
                    if ToMaterialType.state == VRAY_MAT then
                    (
                        local origMtl = meditMaterials[medit.GetActiveMtlSlot()] -- get Active Material Slot
                        setMeditMaterial (medit.GetActiveMtlSlot()) (convert_Mtl_to_Vray origMtl) -- put the material to the slot
                    )
                )
            )
        )
    )
    createDialog Material_Convertor style:#(#style_toolwindow, #style_border, #style_sysmenu)
)

 

0 Likes
Message 35 of 53

Anonymous
Not applicable

Actually it does work perfectly on a simple scene but with a more complex one it gives the following error

 

 

true
-- Error occurred in mat loop; filename: ; position: 4528; line: 81
--  Frame:
--   mat: Concrete - Cast In Situ:Autodesk_Concrete
--   called in convertScene.pressed(); filename: ; position: 4554; line: 81
--  Frame:
--   origMtl: undefined
>> MAXScript Rollout Handler Exception: -- Unable to convert: undefined to type: MaxObject <<

 

 

Thanks for all your help... really appreciated 🙂

 

0 Likes
Message 36 of 53

Anonymous
Not applicable

it does happen only of Concrete - Cast in Situ material... is it because of the long name

0 Likes
Message 37 of 53

Swordslayer
Advisor
Advisor

Could you provide a test scene? The case expression can return undefined when it doesn't find a value in any of the branches. It might be something else, as #Concrete is there, eitherway I'd like to check it.

 

0 Likes
Message 38 of 53

Anonymous
Not applicable

here you go

0 Likes
Message 39 of 53

Swordslayer
Advisor
Advisor

So what exactly doesn't work there? Converting entire scene works for me, individual materials slots too. Any clue on how to reproduce the exception?

0 Likes
Message 40 of 53

Anonymous
Not applicable

just tried it on the scene i sent through and yes it does work....as i was not able to upload the whole scene due to limited file size. sorry i do not know how to send the file through

 

the error i get is

 

-- Error occurred in mat loop; filename:

 A2vray.ms; position: 4528; line: 81
--  Frame:
--   mat: Concrete - Cast In Situ:Autodesk_Concrete
--   called in convertScene.pressed(); filename: 

 A2vray.ms; position: 4555; line: 81
--  Frame:
--   origMtl: undefined
>> MAXScript Rollout Handler Exception: -- Unable to convert: undefined to type: MaxObject <<

0 Likes