Python Material Library

Python Material Library

JokerMartini23
Enthusiast Enthusiast
2,448 Views
6 Replies
Message 1 of 7

Python Material Library

JokerMartini23
Enthusiast
Enthusiast

How in the world can I save a material library i created using Python. In this example below I've created a temporary material library and now I just want to save that mat file to a specified location. I do not want to display the filesave dialog, I want to pass the filepath through code to automate its output location.

 

The documentation doesn't describe much of anything in regards to what args get passed to this method or what it even accepts, for Material Library. Any help would be great!!!

 

thanks

 

filepath = "C:/Users/jmartini/Desktop/Trash/pyss/airplane.mat"

# save each material to it's own library file
matlib = MaxPlus.MaterialLibrary.GetCurrentLibrary()
matlib.DeleteAll()
matlib.Add(self.material)

mat_count = MaxPlus.MaterialLibrary.GetNumMaterials(matlib)
if mat_count:
	saved = matlib.FileSaveMatLib(filepath)
	print saved

 

0 Likes
Accepted solutions (1)
2,449 Views
6 Replies
Replies (6)
Message 2 of 7

denis_grigor
Autodesk Support
Autodesk Support
Accepted solution

Hi John,

 

I am not sure yet that it is possible to silently save the mat file using MaxPlus, but I would suggest you to use the new pymxs module, that basically exposes the MAXScript runtime. The documentation is also close to nothing, but can be easily compensated by the MAXScript documentation.

 

For instance, to handle the Material library and save it silently into a file, in MAXScript you would do:

 

saveMaterialLibrary "my_library.mat"

 

using the pymxs module you would do:

 

import pymxs
rt = mymxs.runtime
rt.saveMaterialLibrary("my_library.mat")

 

The pymxs module is not a replacement for MaxPlus, but merely a new companion.


Denis GRIGOR
Developer Technical Services
Autodesk Developer Network



0 Likes
Message 3 of 7

JokerMartini23
Enthusiast
Enthusiast

This new module is only available in max 2017 and up though correct?

 

0 Likes
Message 4 of 7

denis_grigor
Autodesk Support
Autodesk Support

I took a closer look at the MaxPlus approach and I think there is a way.

 

MaxPlus might not be well documented, but this is wrap of the C++ SDK, so if there are questions like "what args are passed?" I usually take a look at the corresponding C++ method:

 

virtual void FileSaveMatLib(HWND hWnd) 
=========
Remarks
    If the current material library has been saved previously (has been named) this method saves 
the material library to the same file.
Otherwise it brings up the standard Save File As dialog box to allow the user to save the current
material library. Parameters: HWND hWnd : The parent window handle.

 

From this I can conclude that if the file"my_lib.mat" already exists, it will not pop-up the "Save As dialog", so what you could do is to create an empty file and just point to it.

 

 


Denis GRIGOR
Developer Technical Services
Autodesk Developer Network



0 Likes
Message 5 of 7

JokerMartini23
Enthusiast
Enthusiast
So what would that like syntax wise. It still is looking for a hwnd ?
0 Likes
Message 6 of 7

JokerMartini23
Enthusiast
Enthusiast

Hey Denis, how can i do this using MaxPlus then, could you demonstrate how i would actually write the code please?

I have a material I want to save out with to a material library from a specified node. Any help would be great!

 

0 Likes
Message 7 of 7

Anonymous
Not applicable

Wow, that's interesting. I want to try to write some plug-ins in python. 

0 Likes