Notifications
Clear all

[Closed] "Hot" material boolean property?

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
2 Replies

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.

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