Notifications
Clear all
[Closed] Converting Mental Ray Arch & Design Materials
Sep 30, 2016 6:56 am
I’m trying to get all the Mental Ray Architecture and Design materials in a scene and then convert them to Standard materials. Right now my code runs without errors, but the materials don’t convert, but instead remain Mental Ray Arch & Design materials. Anybody know why? Thanks
Brad
(
global MaterialConversionGUIRollout
fn ConvertAllMaterials =
(
--Get all instances of Mental Ray Architecture and Design materials used in the scene and the material editor
archDesignMaterials = getclassinstances Arch___Design__mi
if archDesignMaterials.count > 0 then
(
for mat in archDesignMaterials do
(
format "Found Arch and Design material: %. Trying to convert to Standard Material...
" mat.name
newStandardMaterial = StandardMaterial()
newStandardMaterial.name = mat.name
mat = newStandardMaterial
)
)
else print "No Architecture Design Materials found in scene."
)
--GUI
try(DestroyDialog MaterialConversionGUIRollout) catch()
rollout MaterialConversionGUIRollout "Material Conversion" width:200 height:300
(
--GUI Elements
GroupBox testingGroup "Testing" pos:[5,5] width:195 height:295
button ConvertAllMaterialsButton "Convert Materials" pos:[5,5] width:190 height:25
--GUI Button Handlers
on ConvertAllMaterialsButton pressed do
(
ConvertAllMaterials()
)
)
CreateDialog MaterialConversionGUIRollout
)
3 Replies
Sep 30, 2016 6:56 am
mat = newStandardMaterial is simply changing the mat variable to newStandardMaterial. To change the material you need to replace that material with a new one.
This thread should help with that. Check out denisT or my samples in that thread.
-Eric
Sep 30, 2016 6:56 am
Here is my (noob) code that is working for me, in case anybody wants it:
(
global MaterialConversionGUIRollout
global supportedNonStandardMaterialClasses = #
(
Arch___Design__mi,
Architectural,
Multimaterial
)
fn ConvertMaterialToStandard mat =
(
format "Starting conversion of: %
" mat
newStandardMaterial = undefined
newMaterialName = undefined
newDiffuse = undefined
newDiffuseMap = undefined
if (classof mat == Arch___Design__mi) then
(
format " Converting Arch___Design__mi material properties: %
" mat
if(mat.diff_color != undefined) then ( newDiffuse = mat.diff_color )
if(mat.diff_color_map != undefined) then ( newDiffuseMap = mat.diff_color_map )
)
else if (classof mat == Architectural) then
(
format " Converting Architectural material properties: %
" mat
if(mat.diffuse != undefined) then ( newDiffuse = mat.diffuse )
if(mat.diffuseMap != undefined) then ( newDiffuseMap = mat.diffuseMap )
)
newStandardMaterial = StandardMaterial name: mat.name
if(newDiffuse != undefined) then ( newStandardMaterial.diffuse = newDiffuse )
if(newDiffuseMap != undefined) then ( newStandardMaterial.diffusemap = newDiffuseMap )
newStandardMaterial.showInViewport = true
format " Converting % material to % material
" mat newStandardMaterial
replaceinstances mat(newStandardMaterial)
)
fn ConvertAllMaterials =
(
allNonStandardMaterials = #()
for allMaterialClasses in material.classes do
(
for mat in (getClassInstances allMaterialClasses processAllAnimatables:true) do
(
if (classof mat != Standard) then
(
append allNonStandardMaterials mat
)
)
)
for nonStandardMaterial in allNonStandardMaterials do
(
format "Found non standard material: %
" nonStandardMaterial
nonStandardMaterialClass = classof nonStandardMaterial
format "The class of this material is: %
" nonStandardMaterialClass
for supportedMaterial in supportedNonStandardMaterialClasses do
(
format " Checking if % material class matches %.
" nonStandardMaterialClass supportedMaterial
if(classof nonStandardMaterial == supportedMaterial) then
(
if (classof nonStandardMaterial == Multimaterial) then
(
format " Found multimaterial: %
" nonStandardMaterial
-- This is a multi-sub material, so loop through all submaterials
for i in nonStandardMaterial.materialIdList do
(
submat = nonStandardMaterial[i]
if (classof subMat == Multimaterial) then --Nested Multimaterial
(
format " Found nested sub material: %
" subMat
for i in subMat.materialIdList do
(
nestedSubMat = subMat[i]
if(classof nestedSubMat != Standard) then
(
format " Converting nested sub material: %
" nestedSubMat
ConvertMaterialToStandard nestedSubMat
)
)
)
else
(
if(classof subMat != Standard) then
(
format " Converting sub material: %
" subMat
ConvertMaterialToStandard subMat
)
)
)
)
else
(
format " Converting material: %
" nonStandardMaterial
ConvertMaterialToStandard nonStandardMaterial
)
)
)
)
print "Finished conversion of non-standard materials to standard materials."
)
fn DeleteHiddenObjects =
(
hiddenObjects = for obj in objects where obj.isHidden collect obj
if hiddenObjects.count > 0 then
(
/*
for obj in hiddenObjects do
(
format "Deleting hidden object: %
" obj
delete obj
)
*/
delete hiddenObjects
print "Finished deleting hidden objects."
)
print "No hidden objects found. Nothing deleted."
)
--GUI
try(DestroyDialog MaterialConversionGUIRollout) catch()
rollout MaterialConversionGUIRollout "Material Conversion" width:200 height:300
(
--GUI Elements
GroupBox testingGroup "Testing" pos:[5,5] width:195 height:295
button ConvertAllMaterialsButton "Convert Materials" pos:[5,5] width:190 height:25
button DeleteHiddenObjectsButton "Delete Hidden Objects" pos:[5,35] width:190 height:25
--GUI Button Handlers
on ConvertAllMaterialsButton pressed do
(
ConvertAllMaterials()
)
on DeleteHiddenObjectsButton pressed do
(
DeleteHiddenObjects()
)
)
CreateDialog MaterialConversionGUIRollout
)