If you want to know whether a material is used by any objects in the scene, you can check the UsedBy property.
Here’s a Python snippet that finds unused materials in the current material library:
from siutils import si if Application.Version().split('.')>= "11": si = si() # win32com.client.Dispatch('XSI.Application') from siutils import log # LogMessage from siutils import disp # win32com.client.Dispatch from siutils import C # win32com.client.constants matlib = si.ActiveProject.ActiveScene.ActiveMaterialLibrary for mat in matlib.Items: if mat.UsedBy.Count == 0: log( '%s <Not used>' % mat.Name )
Hi Steve, how are you?
Just one question. Is there an easy way to make this script check if materials are being used in other passes? As far as I see it only checks current pass…
Easy? I guess easy enough, but kinda ugly…I think you would need to cycle through all the passes, making each one current and then checking the UsedBy count.
Or loop over the paritions and see which ones have a material???
Thanks for pointing that out…I forgot about how some things “disappear” when you change the current pass. I noticed the Material Manager
Ok, thank you!!
Thant’s just what I was trying. Cycling though the passes. I thought there could be a “hidden” bit in the sdk to find if it’s being used in any other pass.
Sorry to buzz you again… but I’ve notices that when you try to delete a material that’s not being used in the current pass but it is used in any other pass it alerts you saying you’re going to delete a shared property, so… SI knows about it. Hmmm… There must be a way to access that info. Don’t you think? 😉
Maybe you could check the Owners, to see if there is a partition owner?
I notice that Owners.Count = 2, even for a material applied to a partition in the non-current pass.
You got it! It seems it always has an Owner, which is the Material Library it belongs to, but if it has more than one, those are the partitions (even if they’re empty), groups, etc. where it’s been applied. Thank you!