Looping through all materials and material libraries


Here’s a snippet that shows how to loop through all material libraries and materials and delete unconnected shaders:

var oMatLibs = ActiveProject.ActiveScene.MaterialLibraries;
oEnum = new Enumerator( oMatLibs ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
{
	var oMatLib = oEnum.item() ;
	oEnum1 = new Enumerator( oMatLib.Items ) ;
	for (;!oEnum1.atEnd();oEnum1.moveNext() )
	{
		var oMat = oEnum1.item() ;
		DeleteUnusedShaders( oMat );
	}

}

The same thing but in Python.

oMatLibs = Application.ActiveProject.ActiveScene.MaterialLibraries
for lib in oMatLibs:
	for mat in lib.Items:
		Application.DeleteUnusedShaders( mat )

3 thoughts on “Looping through all materials and material libraries

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s