Notifications
Clear all

[Closed] Loading Material to Material Slot from Library

I’m trying to load a material from a Library .mat file. No success. Seems like it should be pretty straight forward.

Here’s the error:
– Type error: Material library index must be number or name, got: undefined

Thanks,
-=Chris

–Load Material to Material Slot from Library

 loadMaterialLibrary "C:\Users\chris.VHIKITS\Documents\3dsMax\materiallibraries\Test.mat"
 setMeditMaterial 1 redTest --redTest is the name of the Material
 
 --MeditMaterials[1] = currentMaterialLibrary ["redTest"] --Tried this also.
5 Replies

This should works if your matlib file name is correct and if your matlib contains material named “redTest”

matLib = loadTempMaterialLibrary @"C:\Users\chris.VHIKITS\Documents\3dsMax\materiallibraries\Test.mat"
  if matLib != undefined do
  (
  	if (mat = matLib["redTest"]) != undefined do setMeditMaterial 1 mat 
  )

edit: remove spaces in filename

Thanks! Worked great.

-=Chris

You can simply use fn

fn setMEditMat slot: matName: libFile: =
(
	if (matLib = loadTempMaterialLibrary libFile) != undefined do
	(
		if (mat = matLib[matName]) != undefined do setMeditMaterial slot mat 
	)
)

libFilename = @"C:\some_folder\some_lib.mat"
setMEditMat slot:5 matName:"testMat" libFile:libFilename 

Thanks again. That’s great!

-=Chris

Can I load a material (e.g. Wood Pine) from the Autodesk Material Library using Maxscript? If so, how? I am using 3ds Max Design 2014. Thank you