FCurveEditor

Object Hierarchy

Introduced

3.0

Description

This object provides the context information of the Softimage FCurve editor. By using the information exposed by this object, it is possible to write custom fcurve editing scripts or plug-ins which react to user's actions in the FCurve Editor.

In order to access an instance of this object you need to create a custom command with the siCommandCategory set to siFCurveCategory. This command will appear in the edit menu of the fcurve editor so that the user can execute it on demand. The command takes a single argument, which is a pointer to an instance of the FCurveEditor object.

Using the methods and properties of the FCurve and FCurveKey objects the custom command can change the fcurves. The user interface will update automatically to reflect any changes made to the underlying fcurve objects.

The following example demonstrates two custom fcurve editor scripts, and there are more examples in Netview, under XSI Local: Tools: Animate.

Methods

GetEditorAttribute2

GetSelectedKeys2

Properties

EditorAttribute

SelectedFCurves

SelectedKeys

Examples

VBScript Example

'
' Custom FCurve Command Demo
'
'This script demontrates the Softimage support for plugging in a 
'custom command.
'
'Instructions:
'
'1) In order to try this code the commands needs to be saved onto disk in a .vbs 
'file so that it can be registered.
'
'2) install the commands using the following, (changing the path according to your config):
'  xsi -script "C:/temp/FCurveDemo.vbs" -main InstallFCurveCmdExamples -args -Location "c:/temp/FCurveDemo.vbs"
'
'3) Launch Softimage, 
'4) Create some animated parameters, 
'5) Open the fcurve editor, select curves and keys from your animated parameters
'6) Try the FCurveEditorInfo and AvgSelectedPoints commands which will appear in the Edit menu


sub InstallFCurveCmdExamples( Location )
   dim cmd

   'Location argument is expected to be the full path name of the script file 
   'where the commands we are installing are implemented
   logmessage "Installing fcurve editor commands found in " & Location

   'Remove any existing earlier registrations of this command
   Application.RemoveCommand "FCurveEditorInfo"
   Application.RemoveCommand "AvgSelectedPoints" 

   set cmd = Application.CreateCommand("FCurveEditorInfo", siFCurveCategory)
   cmd.Description = "FCurveEditorInfo shows information about FCurve Context"
   cmd.ScriptingName = "FCurveEditorInfo"
   cmd.Handler = "OnFCurveEditorInfo"
   cmd.FileName = Location
   cmd.Language = "VBScript"

   'FCurve callbacks are a sub not a function
   cmd.ReturnValue = false
                                           
   'FCurve commands get a pointer to an FCurveEditor OM object
   cmd.Arguments.Add "FCurveEditor", siArgumentInput, 0, siDispatch

   Application.AddCommand cmd

   logmessage "FCurveEditorInfo is now added to fcurve editor Edit menu"

   set cmd = Application.CreateCommand("AvgSelectedPoints", siFCurveCategory)
   cmd.Description = "AvgSelectedPoints change value of selected keys"
   cmd.ScriptingName = "AvgSelectedPoints"
   cmd.Handler = "OnAvgSelectedPoints"
   cmd.FileName = Location
   cmd.Language = "VBScript"
   cmd.ReturnValue = false
   cmd.Arguments.Add "FCurveEditor", siArgumentInput, 0, siDispatch

   Application.AddCommand cmd

   logmessage "AvgSelectedPoints is now added to fcurve editor Edit menu"

end sub

'This first demo is informative - it logs a bunch of information about the 
'state of the FCurve editor, in effect demonstrating what you can find out

sub OnFCurveEditorInfo( in_objFCurveEditor )
   LogMessage "FCurveEditorInfo called - showing information about current context of FCurve Editor"

   if ( typename( in_objFCurveEditor ) = "Nothing" ) then
       Logmessage "FCurve Argument is NULL"
   elseif ( typename( in_objFCurveEditor ) <> "FCurveEditor" ) then
       LogMessage "FCurve Argument is not an FCurve, it is a " & typename( in_objFCurveEditor ) 
   else
       'Now access the FCurve Context listing the contents.

       dim oCurves, oCurve
       set oCurves = in_objFCurveEditor.SelectedFCurves

       if ( oCurves.Count = 0 ) then
          logmessage "There are no selected fcurves in the editor"
       end if

       dim i, strInfo
       for each oCurve in oCurves

          logmessage "-------------------------------------"

          'build a string description of the frame/keyvalues 
          '(for a real motion capture fcurve this would be too long to display like this)

          strInfo = ""
          for i = 0 to ( oCurve.Keys.Count - 1 )
              strInfo = strInfo & "(" & Round( oCurve.Keys.Item( i ).Time, 3 ) _
                         & ", " & Round( oCurve.Keys.Item( i ).Value, 3 ) & ") "
          next
                 
          LogMessage "Selected FCurve has the following keys: " & strInfo

          'List the selected keys

          dim oKeys, oKey
          set oKeys = in_objFCurveEditor.SelectedKeys( oCurve )

          if ( oKeys.Count = 0 ) then
              logmessage "There are no keys selected on this fcurve"
          else
              strInfo = ""
              for each oKey in oKeys
                 strInfo = strInfo & "(" & Round( oKey.Time, 3 ) & ", " & Round( oKey.Value, 3 ) & ") "
              next
              LogMessage "The following keys are selected on this FCurve: " & strInfo
          end if
       next

       'The user may have selected a region in the fcurve editor.  This information is available like this:

       logmessage "-------------------------------------"

       dim Start, endFrame, Min, Max

       Start = in_objFCurveEditor.EditorAttribute( siRegionStartFrame )
       endFrame = in_objFCurveEditor.EditorAttribute( siRegionEndFrame )
       Min = in_objFCurveEditor.EditorAttribute( siRegionMin )
       Max = in_objFCurveEditor.EditorAttribute( siRegionMax )

       if ( Start <> endFrame ) then
          logmessage "User has selected time region from frame " &_ 
                     round( Start, 2 ) & " to " & round( endFrame, 2 )
       else
          logmessage "No time region is selected"
       end if 

       if ( Min <> Max ) then
          logmessage "User has selected key value range from " &_ 
                     round( Min, 2 ) & " to " & round( Max, 2 )
       else
          logmessage "No Value region is selected"
       end if 

   end if

end sub

'This second demo is action oriented - it changes the state of the FCurves that are selected.
'
'In this case we take the selected keys and set their values to the average.

sub OnAvgSelectedPoints( in_objFCurveEditor )
   LogMessage "AvgSelectedPoints called"

   'Example of some simple error handling
   if ( typename( in_objFCurveEditor ) <> "FCurveEditor" ) then
       LogMessage "Invalid argument to command - Should be FCurveEditor object instead we got a " _ 
                 & typename( in_objFCurveEditor ), siError
       exit sub
   end if

   dim bDidSomething
   bDidSomething = false

   dim oCurves, oCurve
   set oCurves = in_objFCurveEditor.SelectedFCurves

   for each oCurve in oCurves

       dim oKeys, oKey, cntKeys
       set oKeys = in_objFCurveEditor.SelectedKeys( oCurve )

       cntKeys = oKeys.Count

       if ( cntKeys > 1 ) then

          dim sumValues, avgValue
          sumValues = 0

          for each oKey in oKeys
              sumValues = sumValues + oKey.Value
          next

          avgValue = sumValues / cntKeys

          for each oKey in oKeys
              oKey.Value = avgValue
          next

          bDidSomething = true

       end if 
   next

   if ( not bDidSomething ) then
       LogMessage "Please select two or more keys on an fcurve to average"
   end if
end sub

See Also

Command

FCurve



Autodesk Softimage v7.5