PPGLayout.AddFCurve operator

Introduced

v4.0

Description

Adds an FCurve editor to the layout. It should be associated with an FCurve Parameter (see CustomProperty.AddFCurveParameter). This control is a full FCurve editor, and should not be confused with the Animation Divot.

Like other Parameters you can add custom Logic code to the Layout that is called whenever the FCurve changes. This is demonstrated in the examples.

Scripting Syntax

oReturn = PPGLayout.AddFCurve( ScriptName, [Height] );

Return Value

PPGItem

Parameters

Parameter Type Description
ScriptName String Scripting name of the Parameter, which must be of type FCurve. The call does not fail even if no parameter by this name exists. However in that case the control is not drawn as part of the layout.
Height Long Height of the control. Note: It is not necessary to set the width because the control automatically resizes according to the size of the property page.

Default Value: 300

Examples

1. JScript Example

/*
        This example shows how an FCurve can be stored on a Custom Property and UI tools can be added 
        via the PPGLayout object
*/
BuildScene()
function BuildScene()
{
        NewScene( null, false ) ;
        var oCustomProperty = ActiveSceneRoot.AddProperty( "CustomProperty", false, "DataTemplate" ) ;
        oCustomProperty.AddFCurveParameter( "Curve" ) ;
        // Create read-only parameters that will be updated by the logic
        oCustomProperty.AddParameter3( "KeyCount", siInt4,null,null,null,false,true ) ;
        oCustomProperty.AddParameter3( "MaxY", siInt4,null,null,null,false,true ) ;
        // Build the Layout
        var oLayout = oCustomProperty.PPGLayout         
        var oLayoutItem = oLayout.AddFCurve( "Curve", 150 );
        oLayout.AddGroup( "Info" ) ;    
        oLayout.AddRow() ;
        oLayout.AddItem( "KeyCount" ) ;
        oLayout.AddItem( "MaxY" ) ;     
        oLayout.EndRow() ;
        oLayout.EndGroup() ;
        oLayout.AddRow() ;
        oLayout.AddButton( "Randomize" ) ;
        oLayout.AddButton( "Reframe" ) ;
        oLayout.EndRow() ;
        oLayout.Language = "JScript" ;
        oLayout.Logic = OnInit.toString() +
                Randomize_OnClicked.toString() +
                Reframe_OnClicked.toString() +
                ReCalcInfo.toString() +
                Curve_OnChanged.toString() ;
        InspectObj( oCustomProperty ) ;
}
//
// The following code is Logic code for the Property Page
//
function Randomize_OnClicked()
{
        // Get access to the curve
        var oFCurve = PPG.Curve.Value;
        oFCurve.BeginEdit();
        oFCurve.RemoveKeys();
        var maxKeys = 10.0 ;
        var maxX = 100.0 ;
        var maxY = 100.0 ;
        var keys = Math.round( maxKeys * Math.random() ) ;
        for ( var i = 0 ; i < keys ; i++ ) {
                var keyFrame = Math.round( maxX * Math.random() )
                oFCurve.AddKey( keyFrame,
                                                        maxY * Math.random() ) ;
        }
        // Always end back at zero
        oFCurve.AddKey( 0, 0 ) ;
        oFCurve.AddKey( maxX, 0 ) ;
        oFCurve.EndEdit() ;     
        ReCalcInfo() ;
}
function Reframe_OnClicked()
{
        //Redraw, which will reframe the new pset
        PPG.Refresh() ;
}
function ReCalcInfo()
{
        // Show the number of keys and maximum
        // Y value for the curves
        var oFCurve = PPG.Curve.Value;
        PPG.KeyCount.Value = oFCurve.Keys.Count
        var maxYFound = 0 ;
        for ( var i = 0 ; i < oFCurve.Keys.Count ; i++ ) {
                var y = oFCurve.GetKeyValue(i) ;        
                if ( y > maxYFound )  {
                        maxYFound = y ;
                }
        }
        PPG.MaxY.Value = maxYFound ;
}
function Curve_OnChanged()
{
        // Called when every the user changes the FCurve from the user interface.
        ReCalcInfo();
}
function OnInit()
{
        // Called when PPG is first draw, use the opportunity to calculate the initial
        // FCurve values
        ReCalcInfo() ;
}

2. VBScript Example

'
' This example shows how the FCurve control can be customized via SetUIAttribute
' All editors show the same curve but the presentation differs
option explicit
dim oCustomProperty, oLayout, oLayoutItem
set oCustomProperty = ActiveSceneRoot.AddProperty( "CustomProperty",false,"FCurves" )
oCustomProperty.AddFCurveParameter "curve1" 
oCustomProperty.AddFCurveParameter "curve2" 
oCustomProperty.AddFCurveParameter "curve3" 
oCustomProperty.AddFCurveParameter "curve4" 
set oLayout = oCustomProperty.PPGLayout
oLayout.AddRow
oLayout.AddFCurve "curve1", 150
oLayout.AddFCurve "curve2"
oLayout.EndRow
oLayout.AddRow
oLayout.AddFCurve "curve3", 150
oLayout.AddFCurve "curve4", 150
oLayout.EndRow
'Now set attributes
set oLayoutItem = oLayout.Item("curve2")
oLayoutItem.SetAttribute "NoGrid", true
oLayoutItem.SetAttribute "NoRulerX", true
oLayoutItem.SetAttribute "NoRulerY", true
'In order to line up nicely with the 
'other curve in the row set a smaller size (because
'the ruler is not showing
oLayoutItem.SetAttribute "CY", 125
set oLayoutItem = oLayout.Item("curve3")
oLayoutItem.SetAttribute "ViewMinX", -100
oLayoutItem.SetAttribute "ViewMaxX", 100
oLayoutItem.SetAttribute "ViewMinY", 0
oLayoutItem.SetAttribute "ViewMaxY", 150
oLayoutItem.SetAttribute "LabelX", "My X-Axis Label"
oLayoutItem.SetAttribute "LabelY", "My Y-Axis Label"
oLayoutItem.SetAttribute "ColorNonBijective", true
oLayoutItem.SetAttribute "Ghosting", true
'Grid spacing is mostly only a hint to the editor.
'It will ignore values that are too small
set oLayoutItem = oLayout.Item("curve4")
oLayoutItem.SetAttribute "GridSpaceX", 25
oLayoutItem.SetAttribute "GridSpaceY", 25
'Snap Grid is independent of the visible grid
oLayoutItem.SetAttribute "SnapX", 10
oLayoutItem.SetAttribute "SnapY", 10
InspectObj oCustomProperty

See Also

CustomProperty.AddFCurveParameter FCurve PPGLayout.Logic