This reference page is linked to from the following overview topics: Custom Command Wizard.
#include <xsi_command.h>
Represents a Softimage command (either built-in or custom). This object encapsulates information on a command such as the name, category, arguments, where it is implemented etc.
Custom commands behave just like built-in Softimage commands--they are logged in the history window and can be exposed to scripting.
You can access all the built-in and custom commands installed in the system with Application::GetCommands.
Repeat
and
Undo
). You can find the ScriptingName of a
command by running it and then checking the command log. You can
also iterate over the entire collection of commands.Commands are primarily called from scripts, in which case they
are invoked by calling the string returned by Command::GetScriptingName
with the scripting syntax for calling a function. In effect they
appear as if they are helper functions available
to the script writer. For example to call the custom command
Foo
from JScript the syntax is:
Foo( arg1, arg2 );
The C++ API function Application::ExecuteCommand can be used to execute both built-in and custom commands.
You can also place commands in toolbars and menus. There are two ways to place custom commands in Softimage menus. The first is through the command category (see the siCommandCategory enum) and the second, more powerful approach, is through the Menu API.
The arguments that a command accepts are encapsulated in its definition. All commands have a fixed number of arguments, and they are passed to the callback implementing the command in the order to be defined in the ArgumentArray. It is possible to define a default value and an ArgumentHandler for each argument, so commands are often invoked without specifying each argument value explicitly.
Softimage supports three possible ways to define a custom command: the embedded command, the plug-in based command and the v1.5 command. They are all based on the same Command object API but they have some subtle differences. The plug-in based command is the most convenient for commands implemented with the C++ API. For information about the other approaches please see the Command object documentation in the Scripting Reference guide.
The plug-in based approach, new with v4.0, involves implementing the definition and implementation of the custom command inside a self-installed plug-in (see PluginRegistrar::RegisterCommand). Because multiple commands, Menu objects, CustomProperty objects and other elements can all be implemented inside the same .dll (or .so) module, it is often possible to write an entire sophisticated tool inside a single binary file.
Init
callback each time the application is
started. To edit the command definition, change the code inside the
Init
callback and reload the plug-in. To remove the
custom command, remove the plug-in script or dll.// ***************************************************************************** // // Example of Self-installed custom commands. // // Note: For Windows there must also be a .def file as part of the .dsp // and which contains the following contents: // // EXPORTS // XSILoadPlugin @1 PRIVATE // CommandHelloWorldCpp_Init @2 PRIVATE // CommandHelloWorldCpp_Execute @3 PRIVATE // CommandSimpleCpp_Init @4 PRIVATE // CommandSimpleCpp_Execute @5 PRIVATE // CommandSimpleObjectCpp_Init @6 PRIVATE // CommandSimpleObjectCpp_Execute @7 PRIVATE // // // ***************************************************************************** #include <xsi_application.h> #include <xsi_argument.h> #include <xsi_command.h> #include <xsi_context.h> #include <xsi_pluginregistrar.h> #include <xsi_status.h> #include <xsi_x3dobject.h> #include <xsi_model.h> using namespace XSI; #ifdef unix extern "C" #endif CStatus XSILoadPlugin( XSI::PluginRegistrar& in_reg ) { //This function is called by XSI to find out what commands or //other items have been defined inside this dll. in_reg.PutAuthor( L"Softimage" ); in_reg.PutName( L"cppcommanddemo Plug-in" ); in_reg.PutVersion( 1, 0 ); in_reg.RegisterCommand( L"CommandHelloWorldCpp", L"CommandHelloWorldCpp" ); in_reg.RegisterCommand( L"CommandSimpleCpp", L"CommandSimpleCpp" ); in_reg.RegisterCommand( L"CommandSimpleObjectCpp", L"CommandSimpleObjectCpp" ); return XSI::CStatus::OK; } #ifdef unix extern "C" #endif XSI::CStatus CommandHelloWorldCpp_Init( const XSI::CRef& in_context ) { //This function is called to give you the opportunity to define the command. Context ctx(in_context); Command cmd(ctx.GetSource()); cmd.EnableReturnValue( false ) ; // This command takes no arguments return CStatus::OK; } #ifdef unix extern "C" #endif XSI::CStatus CommandHelloWorldCpp_Execute( XSI::CRef& in_context ) { Application app; app.LogMessage( L"Hello world" ) ; // Return a failure status if you want the // calling script to halt return CStatus::OK; } #ifdef unix extern "C" #endif XSI::CStatus CommandSimpleCpp_Init( const XSI::CRef& in_context ) { Context ctx(in_context); Command cmd(ctx.GetSource()); cmd.EnableReturnValue( true ) ; ArgumentArray args = cmd.GetArguments(); // You must mention the arguments you want // The name is not important but must be unique args.Add( L"A" ); args.Add( L"B" ); return CStatus::OK; } #ifdef unix extern "C" #endif XSI::CStatus CommandSimpleCpp_Execute( XSI::CRef& in_context ) { Application app; Context ctxt(in_context); // Access the arguments to the command CValueArray args = ctxt.GetAttribute( L"Arguments" ); CValue argA = args[0] ; CValue argB = args[1] ; // Example of how you can // set the return value of the command CValue returnValue ; if ( argA.m_t == CValue::siString ) returnValue = (CString)argA + (CString)argB ; else returnValue = (double)argA + (double)argB ; ctxt.PutAttribute( L"ReturnValue", returnValue ); return CStatus::OK; } #ifdef unix extern "C" #endif XSI::CStatus CommandSimpleObjectCpp_Init( const XSI::CRef& in_context ) { Context ctx(in_context); Command cmd(ctx.GetSource()); cmd.EnableReturnValue( true ) ; ArgumentArray args = cmd.GetArguments(); args.AddObjectArgument( L"obj" ); return CStatus::OK; } #ifdef unix extern "C" #endif XSI::CStatus CommandSimpleObjectCpp_Execute( XSI::CRef& in_context ) { Application app; Context ctxt(in_context); // Access the arguments to the command CValueArray args = ctxt.GetAttribute( L"Arguments" ); CValue argObj = args[0] ; SIObject argSIObject = (CRef)argObj ; app.LogMessage( L"Name of the input object " + argSIObject.GetName() ) ; // Return a new object as the return value Model root = app.GetActiveSceneRoot(); X3DObject returnObj; root.AddGeometry( L"Grid", L"MeshSurface", L"", returnObj ); ctxt.PutAttribute( L"ReturnValue", returnObj.GetRef() ); // Return a failure status if you want the // calling script to halt return CStatus::OK; } // To try out this example compile and put the resulting dll or // so file in your \Application\Plugins directory or update // the XSI_PLUGINS env variable. // Then run the following JScript code: // Demonstrate the custom commands that are defined in the plug-in DemoCommands() ; function DemoCommands() { // It is simple to execute a custom command, especially one // like this with no return value or arguments. // Will log "Hello World" CommandHelloWorldCpp() ; // Will log "15" logmessage( CommandSimpleCpp( 5, 10 ) ); // Will log "concat" logmessage( CommandSimpleCpp( "con","cat" ) ) ; newscene( null, false ) ; var oSphere = ActiveSceneRoot.AddGeometry("Sphere", "NurbsSurface") ; //Will log: //INFO : "Name of the input object sphere" //INFO : "grid" logmessage( CommandSimpleObjectCpp( oSphere ) ) ; //XSI can also turn an string to an object: //INFO : "Name of the input object grid" //INFO : "grid1" logmessage( CommandSimpleObjectCpp( "grid" ) ) ; }
Command | ( | ) |
Default constructor.
~Command | ( | ) |
Default destructor.
bool IsA | ( | siClassID | in_ClassID | ) | const [virtual] |
Returns true if a given class type is compatible with this API class.
in_ClassID | class type. |
Reimplemented from SIObject.
siClassID GetClassID | ( | ) | const [virtual] |
Creates an object from another object. The newly created object is set to empty if the input object is not compatible.
in_obj | constant class object. |
ArgumentArray GetArguments | ( | ) |
Returns an array of Argument objects defined for this command.
CString GetScriptingName | ( | ) | const |
Returns the scripting name (ScriptingName
) for the
command.
The scripting name is used for executing the command; for example, from a script or by calling Application::ExecuteCommand. Sometimes this string is different from the actual name of the command, which is often used as a label for menu or buttons and may have space characters in it.
Sets the scripting name (ScriptingName
) for the
command. This name should not contain any spaces or start with a
number. To avoid confusion it should be the same or very similar to
the command's name.
in_Str | The new scripting name to set. |
CString GetHandler | ( | ) |
Returns the handler name for a script-based command. The handler specifies the name of the function or subroutine that implements the command. In other words, the Handler is the name of the callback function that Softimage calls each time the command is invoked.
For a command implemented with the C++ API as a self-installed
plug-in this property is not necessary because the handler is
determined based on the name of the command. For example the
handler of HelloWorldCpp
would be
HelloWorldCpp_Execute()
.
Sets the handler name for a script-based command. This is only necessary when defining a custom command that is implemented as a script.
CString GetLanguage | ( | ) |
Returns the language used for implementing this command's handler function. The values can be one of the following:
CPP
(using the Softimage C++ API)C#
(C# using the Softimage Object Model via
.NET)Python
(Python scripting language using the
Softimage Object Model)JScript
(JScript using the Softimage Object
Model)VBScript
(VBScript using the Softimage Object
Model)The caller of a command does not need to be concerned with this property because any command can be called from any supported scripting language, C#, or the C++ API.
Sets the language used for implementing this command. It is not necessary to call this function for a custom command implemented as a self-installed plug-in.
CString GetFileName | ( | ) |
Returns the .dll or script file that implements the command. For many built-in commands this property is not specified.
Sets the name of the file exposing the handler function. The full path should be specified. It is not necessary to set this property for a custom command implemented inside a self-installed plug-in.
CString GetCode | ( | ) |
Returns the implementation of the command. This property only applies to script-based custom commands that are implemented by embedding the code directly in the command definition rather than using an external file. For commands implemented with the C++ API this returns an empty string.
Sets the implementation of a script-based custom command. This is a convenient way to implement small, simple script-based custom commands. The code is stored as part of the Command definition.
bool IsReturnValueEnabled | ( | ) |
Returns true if the custom command returns a value. If you call a command that does not return a value then Softimage always passes an empty CValue as the return value.
CStatus EnableReturnValue | ( | bool | ) |
Many custom commands return values, for example a newly created object or a calculated number. Other custom commands act like void functions in C++ and perform some operation but do not return any information. This function allows you to signal whether the custom command can be expected to return a value or not. The default behavior is true.
CString GetCategory | ( | ) |
Returns a string containing a list of the categories that the command belongs to. This information is similar to SIObject::Categories but this function returns a string delimited with the pipe (|) character rather than an array. Custom commands always belong to the Custom category. If the siCommandCategory argument was specified in the call to Application::CreateCommand then a string representing the specified category will be included in the returned string.
CString GetDescription | ( | ) |
Optionally sets a descriptive string for the command. The description is shown in the Softimage user interface (for example on the Customize Toolbar dialog).
CString GetTooltip | ( | ) |
Optionally sets the tooltip. This text will appear when the mouse hovers over a command button on a toolbar.
CString GetUID | ( | ) |
For advanced users. Returns the GUID that Softimage uses internally to distinguish between different custom commands. This can be used with the CreateToolbarButton command.
bool IsEnabled | ( | ) |
CStatus PutEnabled | ( | bool | ) |
Enables or disables a command. This flag only affects the user interface; it does not block the command from being executed from a script. This property is often used in conjunction with the Menu API. By default all custom commands are enabled.
bool IsBuiltin | ( | ) |
Distinguishes between custom commands and the commands that ship as part of the Softimage application (called either native or built-in commands).
Executes the underlying command.
out_return | The value returned by the underlying command. If the command has no return value explicitly defined, Execute returns all output arguments in a CValueArray object. However, if the command defines a return value, you cannot extract any output arguments from it. This is because the command is not returning an output argument array, but a specific value. You can check the Return Value section in the reference documentation to see whether it uses an explicit return value and what that value is. |
The recommended way to execute a command from the C++ API is to call Application::ExecuteCommand
bool GetFlag | ( | LONG | in_whichflag | ) |
Returns the state of one of the various flags that affects command behavior. You can set the value of a flag with Command::SetFlag.
in_whichflag | Value from the siCommandCapabilities enum |
CStatus SetFlag | ( | LONG | in_whichflag, |
bool | in_newvalue | ||
) |
Sets the state of one of the various flags that affects command behavior. You can test the value of these flags with Command::GetFlag.
in_whichflag | Flag to set. |
in_newvalue | True to enable the flag (default); false to disable it. |
bool SupportsKeyAssignment | ( | ) |
Sets the state of the ::siSupportsKeyAssignment flag (shortcut
for Command::GetFlag(siSupportsKeyAssignment)
).
bool CannotBeUsedInBatch | ( | ) |
Sets the state of the ::siCannotBeUsedInBatch flag (shortcut for
Command::GetFlag(siCannotBeUsedInBatch)
).
bool IsNotLogged | ( | ) |
Sets the state of the ::siNoLogging flag (shortcut for
Command::GetFlag(siNoLogging)
).
CStatus Update | ( | ) |
Commits changes to the current command to the command definition. Subsequent calls to the command need to match the new definition of the command. In other words, this allows you to change the behavior and signature of a command after it is added with Application::AddCommand.
Init
callback and reload the
plug-in using the Plugin Manager dialog.