GetInstanceValue (Parameter)

Introduced

5.0

Description

Returns instance value for specified object. Instance values can only be applied to Property objects that can be shared or Shader objects connected under shared Material objects. For example, the ImageShader.tspace_id parameter is an instance value.

They cannot be animated, so this method doesn't take a time argument. If you attempt to bind to the instance value then the object represented by the String value will be returned. If the object could not be found then an empty variant will be returned.

Scripting Syntax

    Parameter.GetInstanceValue( Object, [Bind] )

C# Syntax

    Object Parameter.GetInstanceValue( Object in_obj, Boolean );

Parameters

Parameter | Type | Description
Object | Object such as a X3DObject | Object nesting the shared property
Bind | Boolean | If the parameter supports object binding then attempt to bind to object specified by the instance value and return the object as the value. Default Value: False

Return Value

Variant

Examples

JScript Example

    /*
       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 using the scene root and with a color at vertices (CAV or VertexColor) property
    var model = Application.ActiveSceneRoot.AddModel();
    model.Name = "MyModel";
    model.AddMaterial( "Phong", true, "MyModelMaterial" );

    var cube = model.AddGeometry( "Cube", "MeshSurface", "MyCube" );
    var cav = cube.ActivePrimitive.Geometry.AddVertexColor( "MyVertexColor" );
    var matCube = cube.Material;

    // You can set a InstanceValue directly on a paremeter using the Parameter.Value property if
    // you accessed the parameter via its object and not via the material library or some other
    // object using the material.
    matCube.Parameters("CAV").Value = cav.Name;

    var matlib = ActiveProject.ActiveScene.ActiveMaterialLibrary;
    Application.LogMessage( "Number of materials in library: " + matlib.Items.Count );

    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;
       }

       Application.LogMessage( mat.FullName + " used by "+  mat.UsedBy.GetAsText() );

       for ( var j=0; j<mat.Parameters.Count; j++ ) {
           var param = mat.Parameters(j);
           if ( param.HasInstanceValue ) {
              var eObjs = new Enumerator( mat.UsedBy );

              // Dump instance values for each object
              for ( ; !eObjs.atEnd(); eObjs.moveNext() ) {
                  var obj = eObjs.item();
                  var instancevalue = param.GetInstanceValue( obj );

                  Application.LogMessage( obj.Name + " " + param.ScriptName + " = \"" + instancevalue + "\"");
              }
           }
       }
    }

    // Expected results:
    //INFO : Number of materials in library 2
    //INFO : Sources.Materials.DefaultLib.Scene_Material is unused
    //INFO : Sources.Materials.DefaultLib.Material used by MyModel.MyCube
    //INFO : MyCube CAV = "MyVertexColor"
    //INFO : MyCube UV = ""

See Also

Parameter.HasInstanceValue | Parameter.IsSupportedInstanceValue | Parameter.SetInstanceValue

Autodesk Softimage v7.5