AnimationSourceItem.SetAsStatic
 
 
 

AnimationSourceItem.SetAsStatic

Description

Sets the source (DataSource) of the AnimationSourceItem as a StaticSource. There are two ways you can use this method:

(1) Specify a new StaticSource source (eg., after creating a new AnimationSourceItem with ActionSource.AddSourceItem() ).

(2) Replace an existing DataSource with a StaticSource source.

C# Syntax

StaticSource AnimationSourceItem.SetAsStatic( Object in_vValue );

Scripting Syntax

oReturn = AnimationSourceItem.SetAsStatic( [Value] );

Return Value

StaticSource

Parameters

Parameter Type Description
Value Variant The value of the static value (has to be a double)

Examples

JScript Example

/*
        This example llustrates some of the different ways you can work with the value of an AnimationSourceItem's
        StaticSource, from creating using AddSourceItem and SetAsStaticValue to editing an existing static value
        using the GetSournce/PutSource combo.
*/
app = Application;
NewScene( null, false );
var root = ActiveSceneRoot;
// New static ActionSource
MakeStaticActionSource();
var n = root.FindChild( "", siNullPrimType );
// Get the ActionSource from the model & instantiate it as a clip
var src = root.Sources(0);
AddClip( root, src );
// Find the clip
var mxr = root.Mixer;
var clp = mxr.Clips(0);
app.LogMessage( "BEFORE source modifications:" );
PrintClipInfo( clp );
// Get the AnimationSourceItem
var srcitems = src.SourceItems;
var oldSrcItem = srcitems(0);
// Use AnimationSourceItem.GetSource to get the StaticSource and then change its value
var sv = oldSrcItem.Source;
sv.Value = 2.5;
// Print the values on the action source after modifications to the source
app.LogMessage( "AFTER source modifications:" );
PrintClipInfo( clp );
// Expected results:
//INFO : BEFORE source modifications:
//INFO : Reporting on Mixer.Mixer_Anim_Track.Action_Clip clip:
//INFO :  - Source used = Sources.Scene_Root.Action
//INFO :  --- SrcItem #0 target = MyAnimatedNull.kine.local.posx and its datasource is a StaticSource
//INFO :             (evaluates to 0)
//INFO :  --- SrcItem #1 target = MyAnimatedNull.kine.local.posy and its datasource is a StaticSource
//INFO :             (evaluates to 1)
//INFO :  --- SrcItem #2 target = MyAnimatedNull.kine.local.posz and its datasource is a StaticSource
//INFO :             (evaluates to 2)
//INFO : 
//INFO : AFTER source modifications:
//INFO : Reporting on Mixer.Mixer_Anim_Track.Action_Clip clip:
//INFO :  - Source used = Sources.Scene_Root.Action
//INFO :  --- SrcItem #0 target = MyAnimatedNull.kine.local.posx and its datasource is a StaticSource
//INFO :             (evaluates to 2.5)
//INFO :  --- SrcItem #1 target = MyAnimatedNull.kine.local.posy and its datasource is a StaticSource
//INFO :             (evaluates to 1)
//INFO :  --- SrcItem #2 target = MyAnimatedNull.kine.local.posz and its datasource is a StaticSource
//INFO :             (evaluates to 2)
//INFO : 
// Convenience funtion to print out information about the clip's source
function PrintClipInfo( in_clip )
{
        var app = Application ;
        // Clip
        app.LogMessage( "Reporting on " + in_clip + " clip:" );
        // Clip's source
        PrintSourceInfo( in_clip.Source );
}
// Convenience function to print out information about the source
function PrintSourceInfo( in_src )
{
        var app = Application ;
        // Source
        app.LogMessage( " - Source used = " + in_src );
        // Source's items
        var itemsRef = in_src.SourceItems;
        for ( var i=0; i<itemsRef.Count; i++ ) {
                var animsrcitm = itemsRef(i);
                app.LogMessage( " --- SrcItem #" + i + " target = " + animsrcitm.Target + " and its datasource is a " + ClassName(animsrcitm.Source) );
                // Underlying data source is an FCurve
                if ( animsrcitm.Source.isclassof(siFCurveID) ) {
                        var fc = animsrcitm.Source;
                        app.LogMessage( "            (evaluates to " + fc.Eval(30.0) + " at frame 30)" );
                }
                // Underlying data source is a StaticSource
                if ( animsrcitm.Source.isclassof(siStaticSourceID) ) {
                        var sv = animsrcitm.Source;
                        app.LogMessage( "            (evaluates to " + sv.Value + ")" );
                }
        }
        // Extra blank line
        app.LogMessage( "" );
}
// Create a simple actionsource based on static values
function MakeStaticActionSource()
{
        var app = Application;
        var root = app.ActiveSceneRoot;
        var n = root.AddNull( "MyAnimatedNull" );
        // Get the relative names for the parameter targets
        var rposx = GetRelativeNameForTarget( n.posx );
        var rposy = GetRelativeNameForTarget( n.posy );
        var rposz = GetRelativeNameForTarget( n.posz );
        // Create an empty action source
        var src = root.AddActionSource();
        // Populate it with a static value using ActionSource.AddSourceItem (default=0.0)
        src.AddSourceItem( rposx );
        // Populate it with a specified static value using ActionSource.AddSourceItem
        src.AddSourceItem( rposy, 1.0, true );
        // Populate it with the default static value, then set a real value later with AnimationSourceItem.SetAsStatic
        var animsrcitem = src.AddSourceItem( rposz );
        animsrcitem.SetAsStatic( 2.0 );
}
function GetRelativeNameForTarget( in_param )
{
        var mdlname = in_param.Model.FullName;
        if ( mdlname == "Scene_Root" ) {
                return in_param.FullName;
        } else {
                var tmp = in_param.FullName;
                var re = new RegExp( mdlname + ".", "i" );
                return tmp.replace( re, "" );
        }
}