[Closed] [example] Save material library file for lower max version
I recently worked on a projects with few friends where each of us are used a different max version. The main problem was how to share material lib [*.mat] file because max not have method to save this type of files in lower version. I wrote two simple fn’s that have helped us to easily exchange are mtl-libs and I hope that this fn’s can be useful to someone. Anyway…
First fn will create empty *.max file where all materials and maps from specified mat lib are stored inside root node, and saved in lower max version.
fn Arguments:
matLibPath – fully specified *.mat file path
tempFilePath – fully specified *.max file path (optionaly).
lowerVersion – specify lower version number (BTW lowest version is 2011)
fn exportMtlLibFromHigherVersions matLibPath: tempFilePath: lowerVersion: =
(
if (matLib = loadTempMaterialLibrary matLibPath) != undefined do
(
mtlDataCA = attributes mtlData
(
parameters libs
(
libname type:#string
maxv type:#integer
mtls type:#materialTab tabSize:0 tabSizeVariable:on
maps type:#texturemapTab tabSize:0 tabSizeVariable:on
)
)
if (custattributes.add rootnode mtlDataCA) do
(
rootnode.mtlData.libname = (getFilenameFile matLibPath)
rootnode.mtlData.maxv = lowerVersion
for m in matLib do
(
case superclassof m of
(
(material): append rootnode.mtlData.mtls m
(textureMap): append rootnode.mtlData.maps m
)
)
)
if tempFilePath == unsupplied do tempFilePath = (getFilenamePath matLibPath)
local tempMaxFile = tempFilePath + "\\" + (getFilenameFile matLibPath)
saveMaxFile tempMaxFile saveAsVersion:lowerVersion
)
)
exportMtlLibFromHigherVersions matLibPath:@"c:\Users\BGA\Desktop\NewLib.mat" tempFilePath: lowerVersion:2012
Load saved file in other (lower) version of 3dsmax and use 2nd fn.
Second fn will collect all stored mats and maps from root node and create new *.mat file.
fn Arguments:
newMatLibFilename – specify new *.mat file path (optionaly)
fn saveMtlLibToLowerVersion newMatLibFilename: =
(
if (isProperty rootnode #mtlData) do
(
if newMatLibFilename == unsupplied do
(
newMatLibFilename = (maxFilePath + rootnode.mtlData.libname + (rootnode.mtlData.maxv as string) + ".mat")
)
if (saveMaterialLibrary newMatLibFilename) do
(
matLib = loadTempMaterialLibrary newMatLibFilename
if matLib.count != 0 do (for i = matLib.count to 1 by -1 do deleteItem matLib i)
for mtl in rootnode.mtlData.mtls do append matLib mtl
for map in rootnode.mtlData.maps do append matLib map
saveTempMaterialLibrary matLib newMatLibFilename
)
)
)
saveMtlLibToLowerVersion()
Probably there is better solution for this problem.
probably there is not… but i can suggest to use xref scene to load upper/lower mat sets. it lets you do it without converting CA data to libraries and it doesn’t need reloading the current scene.
Thanks Denis. I not use XRef that’s why I’m not familiar with this method. I always love to see different aproch so can you show some example if it’s not a problem?