Notifications
Clear all

[Closed] Trying to load materials in editor from mat file

Hello! I am new to MAXscripting, but am trying hard to read the MAXScript reference and learn…I am hoping that you can help me where I can’t understand something…

I am attempting to load materials into slots into the Material Editor. And seem to be stuck or confused.

I use the loadMaterialLibrary to open the specific .mat file I want to use. that was easy.
Next I am attempting to use MeditMaterials[1] = (“Metal Red”) where the 1 is the slot in the Material Editor I want to place it and Metal Red is the name of the material.

I am using Max 2009. My ulimate goal is to make a script where, I can open a specific material file and then automatically apply specific materials to specific layers in the scene. I am willing to learn and do this on my own, but will accept any pointers and suggestions.

Thanks!

4 Replies

For this stage once you have loaded the material library, you have to reference the fact that you are calling from that library. Once you have loaded it, it becomes the current material library, and can be referenced as an array using currentMaterialLibrary

MeditMaterials[1] = currentMaterialLibrary[“Metal Red”]

if you have an array of material names that you want to apply it is very easy to loop through and apply add them to different slots in the material editor



//MatArray is an array containing material names from the current material number, its size must be 24 or less (since there are only 24 material editor slots)
MatArray = #("Metal Red","Metal Green","Metal Yellow","Metal Blue")

for i=1 to MatArray.count do
       (
       MeditMaterials[i] = currentMaterialLibrary[MatArray[i]] 
       )


This sort of code pattern can also be used to reference layers in your scene since they can referenced numerically too!

I think this will all work mate, but I dont have max infront of me to test it!

Let me know how it goes, and post again if you have any more questions.

Good luck!

Rich

Hi there, I have writen some scripts that include some of the stuff you wanted so I’ve picked up all the chunks from those scripts and gather them in one to work like you wanted, here’s the script and you can take a look at the source code to understand it better, feel free to use it and ask any questions, hope it helps

Sorry for the double post but I’ve added a material preview to the script, so you really dont need to pass it over the material editor unless you want to make some changes in the material. I’ve searched for the material preview here in cgtalk and used mostly Bobo’s code so cheers to him for that!

1 Reply
(@machete-theeoriginal)
Joined: 11 months ago

Posts: 0

Wow… Kameleon! This is great stuff!!! I was going to start just making routines to use via Menus and then move onto a GUI. This is such a huge help! Thanks so much…