Material Libraries
 
 
 

3ds Max stores groups of materials in a library file with the .mat file extension. The API provides methods to access the materials stored in these libraries. You can use the methods Interface::LoadMaterialLib() and Interface::SaveMaterialLib(). This class also has a method GetMaterialLibrary() which returns a reference to the currently loaded library. You may then use class MtlBaseLib to access the materials themselves. The sample code below shows how this is done. It loads a materials library, removes a single material, and saves it again.

void TestMaterialLib()
{
   // TODO: Change the path
   TCHAR *n1 = _T("D:\\3DSMAX\\MAPS\\3DSMAX.MAT");
 
   intokay = ip->LoadMaterialLib(n1);
   if (! okay) return;
 
   // Declare this as references since we want to manipulate the
   // orignal material library and not a copy.
   MtlBaseLib &mlib1 = ip->GetMaterialLibrary();
   intindex = mlib1.FindMtlByName(TSTR(_T("Aqua Glaze")));
   if (index != -1)
     mlib1.Remove(mlib1[index]);
 
   ip->SaveMaterialLib(n1);
}