How to check for Unassigned Mat

I am trying to figure out a way to check in the Material library if a material is unassigned, and if it is unassigned assign it to selected object.

I am assuming it will be a while loop to check meditmaterials 1-24 to see if there is an assigned mat. I am just looking for the property I need to check.

Thank you

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Thetyrant's picture

I see where my issue was. I

I see where my issue was. I was thinking that if I created a material in slot 1 that it would overwrite the material that is currently in meditMaterials[1]. I put together a test and I was able to achieve the results that I wanted...

--Create Material- Multi
max mtledit
meditMaterials[1] = Multimaterial ()
meditMaterials[1].name = ObjName
meditMaterials[1].names[1] = "mat"
meditMaterials[1].names[2] = "Top"
meditMaterials[1].names[3] = "Btm"
meditMaterials[1].names[4] = "Rear"
meditMaterials[1].names[5] = "Left"
meditMaterials[1].names[6] = "Front"
meditMaterials[1].names[7] = "Right"

$.material = meditMaterials[1]

Anubis's picture

A few tips

First, to clean up terminology, open this page in the Mxs-help: "Collections > Collection Types > MaterialLibrary Values". As you see, their is 3 system globals described at the begining - currentMaterialLibrary, sceneMaterials, meditMaterials. They a 3 independent Collections. All of them hold material instances, but sceneMaterials hold only all materials applied on the scene. currentMaterialLibrary you can access w/o moving it contents to the MEditor, and if the mat's are in the MEditor anyway then use meditMaterials collection. For example: myMat = meditMaterials[1] -- will assign the mat from 1st ME slot to a variable.

Next, as you say you will check a selection of objects, then searching in the sceneMaterials is not the case here. So you need to 'scan' your the .material property of your selected objects. Something like:
for obj in selection do if obj.mat != undefined or obj.mat.name != myMat.name do obj.mat = myMat;
but... this example code compare only the names of the materials. So this is the next question - what you want to compare.

And finally, why you ever need to check the current state of obj's mat's? If the mat is already applied, adding it again will not change anything, nor yet will slow down the proces, if you do this of course in 1 mapped call, i.e. for ex. just:
selection.material = meditMaterials[1]

I hope this helps.
Cheers!

my recent MAXScripts RSS (archive here)

Thetyrant's picture

I am still bit lost. But I

I am still bit lost. But I will explain a bit more of what I am trying to accomplish.

I want to add additional functionality to my script here: http://www.scriptspot.com/3ds-max/scripts/create-editable-box-on-target

When I click on an object, it will build the new editable poly box, and then I want it to assign a MultiMat, but I want to check to see if the current slot in the MatEditor is open for me to create a MultiMat material.

So I was thinking if I setup a loop that will search for the next available MatSlot in the MatEditor that is *unassigned to scene* then create a MultiMaterial and assign it to current object.

Anubis's picture

...

Hmmm, I also met problems with the terminology you used. What mean if the current slot in the MatEditor is open for me to create a MultiMat material? There no 'closed' slots. You can create new material on any of those 24 slots. I really not understand you :/

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.