Getting the image clips for a material


Given this render tree:

here’s a few snippets of JScript that show how to get the image clips for certain ports on the material (in this example, the diffuse and bump ports):

First, get the image clips from the sub-tree that’s plugged into the bump port:

SelectObj("Sources.Materials.DefaultLib.Material1.Lambert", null, null);

var s = Selection(0);
var sp = s.bump;

oEnum = new Enumerator( sp.Sources(0).Parent.ImageClips ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
{
	var oSelItem = oEnum.item() ;
	LogMessage( classname( oSelItem ) + " " + oSelItem.Name );
}

Second, how to get the image clips when a port uses texture layers:

SelectObj("Sources.Materials.DefaultLib.Material1.Lambert", null, null);

var s = Selection(0);
var sp = s.diffuse;

var tl = s.TextureLayers(0);
var d = tl.TextureLayerPorts("diffuse_port")
if  ( d != null )
{
	LogMessage("diffuse driven by a Texture Layer");
}


oEnum = new Enumerator( tl.Parameters("Color").Source.Parent.ImageClips ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
{
	var oSelItem = oEnum.item() ;
	LogMessage( classname( oSelItem ) + " " + oSelItem.Name );
}