Notifications
Clear all

[Closed] Export obj-material or scene materials to .mat

Aaand…yet another question

How can I export the material of a selected object – or more selected ones – to a single .mat file? The MaxScript help isn’t that helpful, since there’s only described a way how a material can be appended to an existing .mat file.
This way would shorten the process shown in the attached image below tremendously:

Next will be, to collect all materials from the scene and export them to a .mat-file.

Thank you in progress for your help. :wip:

7 Replies

You can access the material library by using currentMaterialLibrary global. So you can reset this material table (loadDefaultMatLib() or loadMaterialLibrary), append materials and save it using saveMaterialLibrary.
See “MaterialLibrary Values” in the MAXScript Reference.

But this way, I would have to put the material in a slot of the material editor first, to read it from the currentMaterialLibrary global.

meditmaterials[1] = $Box01.material

That’s the point I want to walk around.

Well, I can’t really understand the problem but you don’t need to use the meditMaterials global, you can directly append materials to the currentMaterialLibrary global:

loadDefaultMatLib()
 append currentMaterialLibrary $Box01.material

To access it:

$Box01.material = currentMaterialLibrary[1]

I developed a short script for a scene export of all materials, but encounter one problem.

on btn_export_scenemat pressed do
(
	local exp_scenemat_array = #()
	exp_scenemat_array = for exp_scenemat_obj in $* where exp_scenemat_obj.material != undefined collect exp_scenemat_obj					
	loadDefaultMatLib()
	for i=1 to exp_scenemat_array.count do
	(
		append currentMaterialLibrary exp_scenemat_array[i].material
	)
	fileSaveAsMatLib()
)

I need to reset the default material library first, before I can export it, to prevent max from exporting all materials again, if I want to export only one material, with another routine I wrote.
Is there a function or construct for resetting the ‘DefaultMatLib’ ?

If you are working on max 9 or higher besides using the default material library you can use custom material libraries. For that you would have to define your own material library variable, append your materials and then save it using [b]saveTempMaterialLibrary/b. Failing that you can alway reset the current material library by loading an empty .mat for example, but I think the first option is what you are looking for.
Besides that you also have the sceneMaterials material library that holds all the materials in the current scene. It´s a bit buggy but if you are trying to save the scene materials it could be faster than just creating your own array.

On a side note, I am currently working on a material manager, currently in beta stages, that uses .mat files to store the user´s materials (see pic), so let me know if I can be of help… I´ve already hit all kinds of walls down this path =)

Thank you for your tips. Since I want to keep this tool compatible with older versions of max since version 9, loading an empty .mat would be the best option.

… Failing that you can alway reset the current material library by loading an empty .mat for example, but I think the first option is what you are looking for. …

What do I need to do to load an empty .mat file? – Is it necassary to create an empty one first? Is there no option to reset the DefaultMatLib?

Another one would be to do something along the lines of:


FOR mat = 1 to currentMaterialLibrary.count DO
(
	deleteItem currentMaterialLibrary 1
)