PDA

View Full Version : "Hot" material boolean property?


mbousquet
03-03-2007, 06:30 PM
I can't seem to find a way to determine if a material in the Material Editor is assigned to a scene object or not. I know I can loop through all object materials, check for a match to sceneMaterials array, etc. but I was hoping for a single property I could check, like

if meditMaterials[1].assigned do ...

Is there a property hiding somewhere for this?

- Michele

Fabiomussarela
03-04-2007, 12:25 PM
Hi Michele :)

try to use the "refs.dependents" on your material, it will return an array of the nodes your material dependsOn.

If your material is assigned to an object , the first element in the returned array will be the object.

here´s an example, I just made a box and assigned the first material on the material editor to the box.


a = meditMaterials[1]
b = refs.dependents a

will return:
#($Box:Box01 @ [-97.267761,94.535522,0.000000], ReferenceTarget:NodeSelection, ReferenceTarget:Material_Editor, ReferenceTarget:Scene, ReferenceTarget:ReferenceTarget, #materialLibrary())



Now, if the SuperClassOf the first element in the array b is a Geometry, shape, and other types of classes that can receive materials. Your material is assigned to the scene.

:)

mbousquet
03-04-2007, 12:50 PM
Thanks! Here's a nice little script that removes all unassigned materials from the Material Editor, and replaces them with a gray standard material with default name:

for i = 1 to 24 do
(
if (refs.dependents meditMaterials[i]).count <= 2 do
(
matName = (i as string) + " - Default"
meditMaterials[i] = standard name:matName
)
)



- Michele

CGTalk Moderation
03-04-2007, 12:50 PM
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.