Converting Autodesk materials

Converting Autodesk materials

hanselmoniz
Enthusiast Enthusiast
10,447 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,448 Views
52 Replies
Replies (52)
Message 2 of 53

Swordslayer
Advisor
Advisor
There is already http://www.scriptspot.com/3ds-max/scripts/multyconvertor which should handle that. If you want to parse the material manually, note that each autodesk_material allows you to get a generic material using .ConvertToGeneric. Btw. for finding one possible value out of a list, case expression is better than if expression - it would also prevent you from the classic mistake of using assigment to a variable instead (single equal sign) of checking for equality (double equal sign).
0 Likes
Message 3 of 53

hanselmoniz
Enthusiast
Enthusiast
Thanks for your help. I tried to use Multyconverter but it just converts autodesk materials to vray materials and does not take the parameters... i think there is some file you have to edit in order to get the script working well...but im a noob at that...
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 4 of 53

hanselmoniz
Enthusiast
Enthusiast
I'm trying to access the code ConvertToGeneric through script but i do not know how to do it... can you post a code to convert all autodesk materials to autodesk generic materials.. forgive my ignorance
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 5 of 53

Steve_Curley
Mentor
Mentor
Hint. Quote tags are for quoting what others have written, not for posting your own comments.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 6 of 53

hanselmoniz
Enthusiast
Enthusiast
for Autodeskmat in scenematerials do
( if classof Autodeskmat == Autodesk_Material then
Autogeneric = Autodeskmat.ConvertToGeneric
Autogeneric.name = Autodeskmat.name
-- Replace the original material with the new Autodesk material
replaceInstances Autodeskmat Autogeneric)
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 7 of 53

hanselmoniz
Enthusiast
Enthusiast
I have to exclude autodesk_generic materials though. I guess it is best done by hasproperty = convertToGeneric
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 8 of 53

hanselmoniz
Enthusiast
Enthusiast
i do not know why this does not work.. Please can you help
for Autodeskmat in scenematerials do
( if classof Autodeskmat == Autodesk_Material then
(if hasProperty Autodeskmat "ConvertToGeneric" then
() else
Autogeneric = Autodeskmat.ConvertToGeneric
Autogeneric.name = Autodeskmat.name
-- Replace the original material with the new Autodesk material
replaceInstances Autodeskmat Autogeneric)
)
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 9 of 53

Swordslayer
Advisor
Advisor
You probably wanted to use isProperty here but eitherway both generic autodesk material and all the different autodesk material types have the ConvertToGeneric property - and it shouldn't be a problem, if you only replace a given set of materials. Skip the check - and better don't work on the live sceneMaterials collection, collect the materials to an array (or use something like sceneMats = join #() sceneMaterials).
0 Likes
Message 10 of 53

hanselmoniz
Enthusiast
Enthusiast
so this should work fine isnt it. But when i run it on autodesk generic and other autodesk materials it does not convert other autodesk materials
for Autodeskmat in scenematerials do
( if classof Autodeskmat == Autodesk_Material then
Autogeneric = Autodeskmat.ConvertToGeneric
Autogeneric.name = Autodeskmat.name
-- Replace the original material with the new Autodesk material
replaceInstances Autodeskmat Autogeneric)
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 11 of 53

Swordslayer
Advisor
Advisor
Only if the class of all sceneMaterials is Autodesk_Material, otherwise it won't work - your Autogeneric variable would be undefined (just put everything after 'then' in a pair of braces to correct it).
0 Likes
Message 12 of 53

hanselmoniz
Enthusiast
Enthusiast
Actually this code runs fine the first time I open max but if I have to run it again. It does not do anything. Sorry I am a total noob at this..
for Autodeskmat in scenematerials do
( if classof Autodeskmat == Autodesk_Material then
(Autogeneric = Autodeskmat.ConvertToGeneric
Autogeneric.name = Autodeskmat.name
-- Replace the original material with the new Autodesk material
replaceInstances Autodeskmat Autogeneric)
)
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 13 of 53

Swordslayer
Advisor
Advisor
The only thing there that might be causing trouble is that scenematerials collection does not update automatically, so for example after importing some geometry with materials assigned it will be still empty, until the scene is saved (autosave will triger the update too). Other than that there should be nothing that could prevent it from working as expected. Of course, in case of multi/sub materials or other nested materials, it won't work either - if that's your case don't use sceneMaterials, assign the result of getClassInstances Autodesk_material to some variable instead and iterate those materials.
0 Likes
Message 14 of 53

hanselmoniz
Enthusiast
Enthusiast
I don't know why this does not work... i have got all the autodesk materials to an array "autodsk" I do not know how to iterate through that array.
autodsk = getClassInstances Autodesk_material
for i in autodsk do
( Autogeneric = autodsk.ConvertToGeneric
Autogeneric.name = autodsk.name
replaceInstances autodsk Autogeneric)
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 15 of 53

hanselmoniz
Enthusiast
Enthusiast
Just tried this... voila it worked...
autodsk = getClassInstances Autodesk_material
for i = 1 to autodsk.count do
( Autogeneric = autodsk.ConvertToGeneric
Autogeneric.name = autodsk.name
replaceInstances autodsk Autogeneric)
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 16 of 53

Swordslayer
Advisor
Advisor
When you are iterating this way, i.e. for item in collection, access that item then, for example for mat in autodsk do autogeneric = mat.ConvertToGeneric ... you get the idea.
0 Likes
Message 17 of 53

Anonymous
Not applicable
hi

try this...

you must find the right Definition. This is my trick for example: mtl_Definition= findString mtl.DefinitionID "Concrete"

But you can´t easy convert the Maps and Parameters. For this must you know, how a MI-File works and look at the Maps and Values in the MI-File. Second must you hack the Spider_Shader Values from Autodesk. The infos find you in the METASL-Codes. That is not so easy.


fn convert_Mtl_to_mrArchitectural mtl=
(
-- if not classof mtl == Autodesk_Material then
newmtl = mtl

case classof mtl of
(
Autodesk_Material:
( if( not allowMatAuto ) then
(
return()
)

nextmat= on

if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Ceramic"
if mtl_Definition != undefined then
( DefinitionID="Ceramic"
nextmat=off
) else nextmat=on
)

if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Concrete"
if mtl_Definition != undefined then
( DefinitionID="Concrete"
nextmat=off
) else nextmat=on
)

if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Gen"
if mtl_Definition != undefined then
( DefinitionID="Generic"
nextmat=off
) else nextmat=on
)
0 Likes
Message 18 of 53

hanselmoniz
Enthusiast
Enthusiast
Correct me if I'm wrong but does this script check what type of Autodesk Material it is?....Then i will have to correspond material properties to vray material depending on the type of Autodesk material:)... I was trying to use Multyconvertor from scriptspot but Im unable to find the properties of autodesk materials other than Generic
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
Message 19 of 53

Anonymous
Not applicable
hi


The Parameters and Maps, can you only convert, have knowledge about MI-File. The Multyconverter can this not.

The code is only a part of a function.

mtl = is your Autodesk Material

the "case of" routine looks wish of Autodesk Material it is "Metal, Generic, Conrete ...."

Max-Script Documentation:
<Autodesk_Material>.DefinitionID String default: "Generic" -- string;
0 Likes
Message 20 of 53

hanselmoniz
Enthusiast
Enthusiast
Will this do...
fn convert_Mtl_to_mrArchitectural mtl=
(
if not classof mtl == Autodesk_Material then
newmtl = mtl

case classof mtl of
(
Autodesk_Material:
( if( not allowMatAuto ) then
(
return()
)

nextmat= on

if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Ceramic"
if mtl_Definition != undefined then
( DefinitionID="Ceramic"
nextmat=off
) else nextmat=on
)

if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Concrete"
if mtl_Definition != undefined then
( DefinitionID="Concrete"
nextmat=off
) else nextmat=on
)

if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Generic"
if mtl_Definition != undefined then
( DefinitionID="Generic"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Glazing"
if mtl_Definition != undefined then
( DefinitionID="Glazing"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Hardwood"
if mtl_Definition != undefined then
( DefinitionID="Hardwood"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "masonry_CMU"
if mtl_Definition != undefined then
( DefinitionID="masonry_CMU"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Metal"
if mtl_Definition != undefined then
( DefinitionID="Metal"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "MetallicPaint"
if mtl_Definition != undefined then
( DefinitionID="MetallicPaint"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Mirror"
if mtl_Definition != undefined then
( DefinitionID="Mirror"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Plastic_Vinyl"
if mtl_Definition != undefined then
( DefinitionID="Plastic_Vinyl"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Solid_glass"
if mtl_Definition != undefined then
( DefinitionID="Solid_glass"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Stone"
if mtl_Definition != undefined then
( DefinitionID="Stone"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "Wall_paint"
if mtl_Definition != undefined then
( DefinitionID="Wall_paint"
nextmat=off
) else nextmat=on
)
if nextmat then (
mtl_Definition= findString mtl.DefinitionID "water"
if mtl_Definition != undefined then
( DefinitionID="water"
nextmat=off
) else nextmat=on
)
)
)
)
---CERAMIC MATERIAL
if DefinitionID = "Ceramic" then
( --Autodesk Ceramic Material properties
--ceramic
newmtl.Diffuse=mtl.Ceramic_Color
mtl.Ceramic_Color_Option = 1
newmtl.texmap_diffuse=mtl.Ceramic_Color_Map
newmtl = mtl ())
3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes