CreateCommand (XSIApplication)

Description

Defines a new custom command in Softimage. A new Command object is returned and can be used to define the command. This definition includes the location of the implementation (Command.FileName), and the arguments that command takes (ArgumentCollection.Add). After the definition of the command has been completed the XSIApplication.AddCommand method must be called to actually register the command in Softimage.

Note: The recommended way to create custom commands is to define them as part of a self-installed plug-in. See PluginRegistrar.RegisterCommand.

Scripting Syntax

    XSIApplication.CreateCommand( Name, [Category] )

C# Syntax

    Command XSIApplication.CreateCommand( String in_name, siCommandCategory in_category );

Parameters

Parameter | Type | Description
Name | String | The unique name identifying the new command. Note: The command is not created if one with this name already exists.
Category | siCommandCategory | Where (on which Softimage standard menu) the command will appear in the user interface. For more information, see the siCommandCategory enum documentation.

Return Value

Command

Examples

JScript Example

    //-------------------------------------------------------------------
    // This example defines & runs a custom command examples
    //
    //
    // README: Copy and paste the example into the script editor
    // and run (F5).
    //
    // The command will be listed in the customize toolbar dialog in
    // the 'Custom Commands' group.
    //-------------------------------------------------------------------
    function ExCreateCommandDemo()
    {
       Application.RemoveCommand("XYZ");

       var cmd = Application.CreateCommand("XYZ");

       cmd.Description = "XYZ custom command.";
       cmd.ScriptingName = "XYZ";
       cmd.Handler = "OnXYZCommand";
       cmd.FileName = filename;
       cmd.Language = "JScript";
       cmd.Arguments.Add( "argument0" );

       Application.AddCommand( cmd );

       // call command
       XYZ( "this is a string argument" );
    }

    // This sample defines the XYZ command's function handler"
    function OnXYZCommand( in_arg )
    {
       LogMessage( "Executing XYZ command with the argument: " + in_arg );
    }

    //--------------------------------------------------------------------
    // Code to bootstrap example into system
    //--------------------------------------------------------------------
    function ExampleSourceCode()
    {
       return "//XSISDK Doc Example\n" +
           OnXYZCommand.toString();
    }

    // if we are running from script editor save code to
    // examples addon folder in the user's directory.
    if (GetUserPref("ScriptingSessionActive"))
    {
       var ex_name  = "ExXSIApplicationCreateCommand";
       var ex_subfolder  = "Scripts";
       var ex_folder  = "XSISDKDocExamples";
       var ex_langsuffix = ".js";

       CreateAddonDirectories( InstallationPath(siUserPath), ex_folder );

       var fso = XSIFactory.CreateActiveXObject("Scripting.FileSystemObject");

       var filename = XSIUtils.BuildPath(
           InstallationPath(siUserAddonPath),
           ex_folder,
           "Data",
           ex_subfolder,
           ex_name+ex_langsuffix );

       if (!fso.FileExists(filename))
       {
           var f = fso.CreateTextFile ( filename );
           f.write( ExampleSourceCode() );
           f.close();
       }

       // run demo
       ExCreateCommandDemo();
    }

See Also

XSIApplication.AddCommand | Command | ArgumentCollection | Argument

Autodesk Softimage v7.5