View Full Version : Next MeditMaterial Free Slot

06 June 2008, 10:32 AM
Hello there,

i'm with a script to import some models into 3ds. I load them from file and i'd like add their material properties to a new empty slot in the material editor. I've been looking at maxscript help but i only found methods to index the materials and assign new values.

The problem is that it could be another scene loaded, so when i import a new object i dont really know if the slot 1 is the one i need, o worst, if the designer added the material in the slot 10 because he had a bad day counting slots :P.

I've done a loop to check the value of the empty slots but i get for example: 03 - Default:Standard when the third slot is empty, but also: 02 - Default:Standard when the second is used. I excepted find something like undefined :P.

Any idea?

Thanks in advance.

06 June 2008, 11:01 AM
You do know that you can load and unload materials from slots don't you? Some people seem to think that max can only have 24 materials. The scene can hodl as many as you like, it's just that you can only view 24 at any one time.

Regarding your question, how would you define a "free" material slot? You could check that there's no maps, or the values are at 100, or maybe that the numbers in the name match the slot index, but "free" is a subective term!

From 3dsmax's point of view, a "free" material is just a standard material that hasn't been changed in any way. (thena again, some people may have their maxstart.max scene set up so that they have 24 materials of a different type, so it's difficult to make a one-size-fits-all case.

Perhaps you could make a pallete that has an interface that lets the designer choose for himeself?

Hope that helps.


06 June 2008, 11:11 AM
Yes, we can manage more than 24 materials, so as you said, "free" is a subective term. Make the pallete was the last of my choises but sometimes programmer must work a bit :).

We can get a professional solution with this option, thanks for the suggestion.


06 June 2008, 11:36 AM
If by free you mean a slot whose material is not applied to any object, then you could use
this :

theDepNodes = #()
theFreeSlots = #()
for i = 1 to 24 do
theSlotMat = meditMaterials[i]
theDepNodes = (refs.dependents theSlotMat immediateOnly:true)
if superClassof theDepNodes[1] != GeometryClass then
print ("\nSlot: " + i as string + " is Free");
append theFreeSlots i
print ("\nSlot: " + i as string + " is Not Free");

print theFreeSlots

06 June 2008, 01:18 PM
Ey dude, thanks for the code. I tested it with some basic objects and it work as i excepted. It doesnt work with the models i imported. I'm missing some parameter when i load and apply the material. I'll focus on this issue for it before go on :).

Thanks again.

06 June 2008, 01:41 PM
And you can of course, wrap the martials part of the import in an undo, so the user could effectively "Undo Material Editor update" if it didn't work as expected.

06 June 2008, 11:34 AM
Finally it's working as i wanted! :)

I still need lot of maxscript skill, but in the example code, you were looking for GeometryClass at first position in depNodes, but in the way we are loading materials from file it was in a different position. So we modified it to fit the situation:

--Find the first material-slot free, understanding free without referencies with an object
fn FindFreeMaterialSlot =
theDepNodes = #() --Array of dependences

for i = 1 to meditmaterials.count do
theDepNodes = (refs.dependents meditMaterials[i]) --All dependences of each material channel

Free = true
for j = 1 to theDepNodes.count do
if superClassof theDepNodes[j] == GeometryClass do
Free = false --Ocuped slot

if Free == true do
return i --Return index of free slot

return undefined --No free slot

Thanks you all!

CGTalk Moderation
06 June 2008, 11:34 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.