v5.0
Returns a Boolean value
indicating whether the parameter is an instance value (true) or not
(false). An instance parameter is a parameter belonging to an
object that can be shared but which can have a unique value for
each place that it is shared.
Instance values include: ImageShader.tspace_id,
Material.ImageClipName, Material.UV, Material.CAV. For example, the
material is owned by the MaterialLibrary but may be used by many
objects. Each object may have a unique value for the
ImageShader.tspace_id parameter.
// get accessor Boolean rtn = Parameter.HasInstanceValue; |
/* This example illustrates how to detect all parameters that support instance values and determine which parameters are currently in use based on the usage of the material. Parameters with instances values include: ImageShader.tspace_id, Material.ImageClipName, Material.UV, Material.CAV. */ NewScene( null, false ); // Create an object with its own material var cube = Application.ActiveSceneRoot.AddGeometry( "Cube", "MeshSurface", "MyCube" ); var mat = cube.AddMaterial( "Blinn", false, "MyMaterial" ); // Create an object with a material on a polygon cluster var torus = Application.ActiveSceneRoot.AddGeometry( "Torus", "MeshSurface", "MyTorus" ); var cluster = torus.ActivePrimitive.Geometry.AddCluster( siPolygonCluster, "MyPolygonCluster" ); var clsmat = cluster.AddMaterial( "Phong", false, "MyMaterialOnCluster" ); // This object will get the material from the scene root. var sphere = Application.ActiveSceneRoot.AddGeometry( "Sphere", "MeshSurface", "MySphere" ); // Create an unused material SICreateMaterial( "Lambert", "UnusedMaterial" ); var matlib = Application.ActiveProject.ActiveScene.ActiveMaterialLibrary; for ( var i = 0; i < matlib.Items.Count; i++ ) { var mat = matlib.Items(i); if ( mat.UsedBy.Count == 0 ) { Application.LogMessage( mat.fullname + " is unused" ); continue; } for ( var j = 0; j < mat.Parameters.Count; j++ ) { var param = mat.Parameters(j); if ( param.HasInstanceValue ) { var colUsedBy = XSIFactory.CreateObject( "XSI.Collection" ); colUsedBy.AddItems( mat.UsedBy ); colUsedBy.RemoveItems( Application.ActiveSceneRoot ); // Don't consider scene material in use - if there are no renderable objects. if ( colUsedBy.Count == 0 ) Application.LogMessage( param.FullName + " belongs to the scene material and is currently unused" ); else Application.LogMessage( param.FullName + " is an instance value and is being used by " + colUsedBy.GetAsText() ); } } } // Expected results: //INFO : Sources.Materials.DefaultLib.Scene_Material.CAV is an instance value and is being used by MyTorus,MySphere //INFO : Sources.Materials.DefaultLib.Scene_Material.UV is an instance value and is being used by MyTorus,MySphere //INFO : Sources.Materials.DefaultLib.Material.CAV is an instance value and is being used by MyCube //INFO : Sources.Materials.DefaultLib.Material.UV is an instance value and is being used by MyCube //INFO : Sources.Materials.DefaultLib.Material1.CAV is an instance value and is being used by MyTorus.polymsh.cls.MyPolygonCluster //INFO : Sources.Materials.DefaultLib.Material1.UV is an instance value and is being used by MyTorus.polymsh.cls.MyPolygonCluster //INFO : Sources.Materials.DefaultLib.UnusedMaterial is unused |