Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Maxunderground news unavailable

[Maxscript] Get all scene materials and save to individual .mat files?
show user profile  jpedleham
Im working on a batch script to convert folders of .mat files from one renderer to another.
I just want to make sure before i get too far into it that what i envisage can infact be done.

I want to grab all of the materials in a scene and one by one save them as a separate mat file.
Can this be done?
Ive seen plenty of scripts that will save them all into one mat, but obviously thats not what im after.
Can anyone confirm this can be done?

read 356 times
11/1/2016 10:00:38 AM (last edit: 11/1/2016 10:00:38 AM)
show user profile  br0t
Yes you can do that. A .mat file or material library is basically just a container for any number of materials, so no one is stopping you from storing a single material in it. You just need to create a library for every material.

for mat in sceneMaterials do (
local matlib = materialLibrary mat
local filepath = @"C:\matlibs" + "\\" + + ".mat"
saveTempMaterialLibrary matlib filepath

never get low & slow & out of ideas

read 345 times
11/1/2016 11:53:06 AM (last edit: 11/1/2016 11:55:59 AM)
show user profile  jpedleham
Oh, its that simple?!
I was putting all materials in a temp library and thats where i was getting stuck.
brilliant thanks br0t :D
read 338 times
11/1/2016 1:22:00 PM (last edit: 11/1/2016 1:22:00 PM)
show user profile  jpedleham
I dont suppose anyone could help me out with a snippet for creating and then offsetting a box?
Its very simple im sure but im still getting my head around doing more than file operations in maxscript.

Im basically importing a load of mat files, assigning them to boxes that are created for each file and then running a converter and exporting the mat files again. This currently works (in my VMS file)

libFile = getsavepath caption:"Select a matlib folder"
filestring = libfile as string
files = getFiles (libfile + "\\*.mat")
for f in files do
if (libFile != undefined) then (
local tempLib = loadTempMaterialLibrary f
if (tempLib == undefined) then ( messagebox "Could not load material library file" title:"Error 001 - Could not load matlib files" )

local mat = tempLib[1]
mybox = box length:20 width:20 height:20
mybox.material = mat



for mat in sceneMaterials do
local matlib = materialLibrary mat
savemats = getsavepath caption:"Select a save folder"
local filepath = (savemats + "\\" + + "_crn" + ".mat")
saveTempMaterialLibrary matlib filepath

read 317 times
11/2/2016 12:23:33 PM (last edit: 11/2/2016 12:23:33 PM)
show user profile  Garp
Add to the definition of mybox something like pos:[10,20,30] or whatever offset you need.

read 312 times
11/2/2016 1:35:22 PM (last edit: 11/2/2016 1:35:22 PM)
show user profile  jpedleham
Thanks garp but what i need is an offset of 25 on the Y axis relative to the last position. basically so it generates boxes in a line with even spacing. I will keep trying but i might not actually need to do that now the more i think about it.

read 310 times
11/2/2016 1:53:23 PM (last edit: 11/2/2016 1:53:23 PM)
#Maxforums IRC
Open chat window