Object Hierarchy | 関連する C++クラス:Command
コマンド
v2.0
Softimage コマンド(ビルトインコマンドまたはカスタムコマンド)ですこのオブジェクトは名前、カテゴリ、引数、実装される場所など、コマンドの情報をカプセル化します。カスタム コマンドは Softimage ビルトイン コマンドのように動作します。履歴ウィンドウに記録され、スクリプトに表示されます。
XSIApplication.Commandsプロパティは、システムのビルトインとインストールされたカスタムコマンドすべてへのアクセスを提供します。たとえば、Translate コマンドの定義を取得するには、'set oCmd = Commands( "Translate" )'を実行します。
コマンドプロパティは、Command.ScriptingNameではなくSIObject.Nameによって、コマンドを見つけます。目的のコマンドを実行して[編集]メニューを確認すると、そのコマンドの名前がわかります。[Repeat]と[元に戻す]の間には常に前回実行されたコマンドの名前が表示されます。コマンドのコレクション全体を反復することも可能です(以下の 1 番目の例を参照)。
スクリプト名によってコマンドを検索するには、XSIApplication.GetCommandByScriptingNameを使用します。また、コマンドを実行した後にコマンドログを確認すると、そのコマンドの ScriptingName がわかります。
コマンドは、主にスクリプトから呼び出されます。つまり、関数を呼び出すスクリプティング構文を使用してCommand.ScriptingNameを呼び出すことにより起動されます。実質的にはスクリプト開発者が使用できる「ヘルパー関数」と同じように見えます。たとえば、"Foo"というカスタムコマンドを JScript から呼び出す場合の構文は"Foo( arg1, arg2 );"ですが、Netviewページに埋め込まれたスクリプトにはこの構文は機能しません。ただし、Applicationオブジェクト(oApplication.Foo( arg1, arg2 ) ;など)のメソッドとしてすべてのコマンドを呼び出すことができます。また、Command.Executeメソッドからもコマンドを呼び出すこともできます。
ツールバーにコマンドを配置することもできます(「CreateToolbarButton」を参照)。Softimage メニューにカスタムコマンドを配置するには、2 つの方法があります。1 つ目はコマンドカテゴリ(siCommandCategoryを参照)を使用する方法、2 つ目はMenuを使用する、より強力な方法です。
コマンドが認識するArgumentは、定義の一部です。すべてのコマンドには固定数の引数があり、ArgumentCollectionで定義された順序で、コマンドを実装するコールバックに渡されます。それぞれの引数についてデフォルト値やArgumentHandlerを定義できるので、明示的に個々の引数の値を指定しなくてもコマンドを実行できる場合があります。
Softimage ではカスタムコマンドを定義する方法として、組み込みコマンド、プラグインベースのコマンド、V1.5 コマンドの 3 つをサポートしています。これらはすべて同一の Command オブジェクト API をベースにしていますが、わずかな違いがあります。
V4.0 の新機能である組み込みコマンドを使用した方法では、コマンドの実装コードを定義の内部に直接保存します(Command.Code を参照)。この方法は単純なコマンドに最適で、Command および Argument オブジェクトを使用した例で広く使用される方法です。コマンド定義は.DSDynamicCommandMap ファイルに継承され、xsiaddon ファイル内にパッケージングすることによって他のマシンに転送されます。この種のコマンドは、CreateAndEditCommandを使用してインタラクティブに作成できます。コマンド定義はEditCommandを呼び出すことによってインタラクティブに変更できます。XSIApplication.RemoveCommandの呼び出しによって破棄することができます。
プラグインベースの方法もV4.0 の新機能です。これは定義を実装し、自己インストールプラグイン(PluginRegistrar.RegisterCommandおよびCommand.Enabledの例とインストールの一部の SimpleCommand を参照)の内部でカスタムコマンドを実装します。この方法は、複雑なスクリプトや C++の API をサポートするスクリプトに適しています。複数のコマンド、Menu、CustomPropertyオブジェクト、およびその他のエレメントを同一のPluginモジュール内ですべて実装できるので、高機能なツールを 1 つのスクリプトファイルまたはdll内にすべて定義できる場合があります。この方法で定義されたコマンドは.DSDynamicCommandMap ファイルには継承されないので、代わりにアプリケーションが開始されるたびにInitコールバックを呼び出してコマンド定義を再生成します。コマンド定義を編集するためには、Init コールバックの内部コードを変更するかプラグインを再ロードしてください。カスタムコマンドを削除するためにはプラグインのスクリプトまたは dll を削除してください。
v1.5 で導入された古いワークフローは、まだ全面的にサポートされています。この方法でカスタム コマンドを定義するステップは、次のとおりです。
(1) XSIApplication.CreateCommand でコマンド オブジェクトを作成します。
(2)プロパティを使用してコマンド オブジェクトのプロパティを定義します。(Command.Language、Command.ReturnValue、Command.SetFlagなど)。
(3) ArgumentCollection.AddまたはArgumentCollection.AddObjectArgumentを使用して指定する引数をすべて追加します(例:myCommand.Arguments.Add "myArgName"、siArgumentInput, true、siBool)。
(4) ディスク上にスクリプトファイルを作成し(Command.FileName)、関数を作成します(Command.Handler)。この関数は、ArgumentCollectionで指定された同じ引数の数値を使用します。Command.ReturnValueが true の場合は値を戻すことができます。
(5) XSIApplication.AddCommandを使用して Softimage にコマンドを登録します。
(6) コマンドはすぐに使用することができます。コマンドが今後の Softimage セッションで使用できるように、Softimage は自動的にコマンド定義を格納します。
(7) XSIApplication.RemoveCommandを呼び出して 2~-5 の手順を繰り戻すか、Command.Updateを呼び出して、コマンドの定義を変更します。
(8) Softimage からコマンドを削除するには、XSIApplication.RemoveCommandを使用します。
注:カスタムコマンドをアドオンとしてパッケージングする方法については、「Add-on Packages」を参照してください。
// JScript Custom Command overview - Embedded Approach
InstallCommands();
DemoCommands() ;
// Comment out this line if you want to experiment with the
// commands created in this example
CleanupCommands();
function InstallCommands()
{
// Remove any existing copies of the demo commands
CleanupCommands() ;
// each command needs to be defined.
// (Softimage will not forget this information
// until they are removed with a call to CleanupCommands() ;
//
// Define Command #1 : CommandHelloWorld
//
var cmd = Application.CreateCommand( "CommandHelloWorld" )
cmd.ScriptingName = "CommandHelloWorld" ;
cmd.Language = "JScript" ;
cmd.ReturnValue = false ;
cmd.Handler = "HelloWorld" ;
cmd.Code = HelloWorld.toString() ; // Embed the code directly in the definition
Application.AddCommand( cmd ) ;
//
// Define Command #2 : CommandSimple
//
cmd = Application.CreateCommand( "CommandSimple" )
cmd.ScriptingName = "CommandSimple" ;
cmd.Language = "JScript" ;
cmd.ReturnValue = true ;
cmd.Handler = "Simple" ;
cmd.Code = Simple.toString() ; // Embed the code directly in the definition
// You must mention the arguments you want.
// The name is not important but must be unique
cmd.Arguments.Add("a")
cmd.Arguments.Add("b")
Application.AddCommand( cmd )
//
// Define Command #3 : CommandSimpleObjectArg
//
cmd = Application.CreateCommand( "CommandSimpleObjectArg" )
cmd.ScriptingName = "CommandSimpleObjectArg" ;
cmd.Language = "JScript" ;
cmd.ReturnValue = true ;
cmd.Handler = "SimpleObjectArg" ;
cmd.Code = SimpleObjectArg.toString() ; // Embed the code directly in the definition
cmd.Arguments.AddObjectArgument("obj");
Application.AddCommand( cmd )
}
function DemoCommands()
{
// It is simple to execute a custom command, especially one
// like this with no return value or arguments.
// Will log "Hello World"
CommandHelloWorld() ;
// Will log "15"
logmessage( CommandSimple( 5, 10 ) );
// Will log "concat"
logmessage( CommandSimple( "con","cat" ) ) ;
newscene( null, false ) ;
var oSphere = ActiveSceneRoot.AddGeometry("Sphere", "NurbsSurface") ;
//Will log:
//INFO : "Name of the input object sphere"
//INFO : "grid"
logmessage( CommandSimpleObjectArg( oSphere ) ) ;
//Softimage can also turn an string to an object:
//INFO : "Name of the input object grid"
//INFO : "grid1"
logmessage( CommandSimpleObjectArg( "grid" ) ) ;
}
function CleanupCommands()
{
Application.RemoveCommand( "CommandHelloWorld" ) ;
Application.RemoveCommand( "CommandSimple" ) ;
Application.RemoveCommand( "CommandSimpleObjectArg" ) ;
}
// Implementation of CommandHelloWorld
// The name of this function matches the string we provided as cmd.Handler
function HelloWorld()
{
LogMessage( "Hello World" ) ;
}
function Simple( in_a, in_b )
{
return in_a + in_b ;
}
function SimpleObjectArg( in_obj )
{
logmessage( "Name of the input object " + in_obj.Name ) ;
// return a different object
return ActiveSceneRoot.AddGeometry("Grid", "MeshSurface") ;
} |
// JScript Custom Command overview - Self-Installed Approach
//
// This example relies on a script on disk so you need to
// follow an important step first before running this example:
//
// SAVE the following commented out code into commandexample.js
// inside your %XSI_USERHOME%\Application\Plugins directory.
//
// Once you have saved the file you can run the script
/*
// BEGINNING OF CODE TO SAVE IN FILE
function XSILoadPlugin( in_reg )
{
in_reg.Author = "Softimage SDK Team" ;
in_reg.Name = "SDK Example - Custom Commands" ;
in_reg.Major = 1 ;
in_reg.Minor = 1 ;
in_reg.RegisterCommand( "CommandHelloWorld", "CommandHelloWorld" );
in_reg.RegisterCommand( "CommandSimple", "CommandSimple" );
in_reg.RegisterCommand( "CommandSimpleObjectArg", "CommandSimpleObjectArg" );
return true ;
}
//
// Define Command #1 : CommandHelloWorld
//
function CommandHelloWorld_Init(in_oCtxt)
{
var cmd = in_oCtxt.Source ;
cmd.ReturnValue = false ;
// We don't need to set cmd.Language, cmd.Handler, cmd.Code
// or cmd.FileName because this is automatically determined.
// Application.AddCommand is not called
// This command takes no arguments
}
//
// Define Command #2 : CommandSimple
//
function CommandSimple_Init(in_oCtxt)
{
var cmd = in_oCtxt.Source ;
cmd.ReturnValue = true ;
// You must mention the arguments you want.
// The name is not important but must be unique
cmd.Arguments.Add("a")
cmd.Arguments.Add("b")
}
//
// Define Command #3 : CommandSimpleObjectArg
//
function CommandSimpleObjectArg_Init(in_oCtxt)
{
var cmd = in_oCtxt.Source ;
cmd.ReturnValue = true ;
// You must mention the arguments you want.
// The name is not important but must be unique
cmd.Arguments.AddObjectArgument("obj");
}
// Implementation of CommandHelloWorld
function CommandHelloWorld_Execute()
{
LogMessage( "Hello World" ) ;
}
function CommandSimple_Execute( in_a, in_b )
{
return in_a + in_b ;
}
function CommandSimpleObjectArg_Execute( in_obj )
{
logmessage( "Name of the input object " + in_obj.Name ) ;
// return a different object
return ActiveSceneRoot.AddGeometry("Grid", "MeshSurface") ;
}
// END OF CODE TO SAVE IN FILE
*/
// This loads the newly created file, which will define the commands inside Softimage.
// It is unnecessary if you restart Softimage or use the Plugin Manager view
Application.LoadPlugin( Application.InstallationPath( siUserPath ) +
"/Application/Plugins/commandexample.js" ) ;
// 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"
CommandHelloWorld() ;
// Will log "15"
logmessage( CommandSimple( 5, 10 ) );
// Will log "concat"
logmessage( CommandSimple( "con","cat" ) ) ;
newscene( null, false ) ;
var oSphere = ActiveSceneRoot.AddGeometry("Sphere", "NurbsSurface") ;
//Will log:
//INFO : "Name of the input object sphere"
//INFO : "grid"
logmessage( CommandSimpleObjectArg( oSphere ) ) ;
//Softimage can also turn an string to an object:
//INFO : "Name of the input object grid"
//INFO : "grid1"
logmessage( CommandSimpleObjectArg( "grid" ) ) ;
} |
// JScript Custom Command overview - v1.5 Approach
//
// This example relies on a script on disk so you need to
// follow an important step first before running this example:
//
// SAVE the following commented out code as
// %XSI_USERHOME%\Data\Scripts\commandexample.js
//
// Once you have saved the file you can run the script
/*
// BEGINNING OF CODE TO SAVE IN FILE
// Implementation of CommandHelloWorld
// The name of this function matches the string we provided as cmd.Handler
function HelloWorld()
{
LogMessage( "Hello World" ) ;
}
function Simple( in_a, in_b )
{
return in_a + in_b ;
}
function SimpleObjectArg( in_obj )
{
logmessage( "Name of the input object " + in_obj.Name ) ;
// return a different object
return ActiveSceneRoot.AddGeometry("Grid", "MeshSurface") ;
}
// END OF CODE TO SAVE IN FILE
*/
InstallCommands();
DemoCommands() ;
// Comment out this line if you want to experiment with the
// commands created in this example
CleanupCommands();
function InstallCommands()
{
// Remove any existing copies of the demo commands
CleanupCommands() ;
// each command needs to be defined.
// (Softimage will not forget this information
// until they are removed with a call to CleanupCommands() ;
var fileNameWithPath = Application.InstallationPath( siUserPath ) + "/Data/Scripts/commandexample.js"
//
// Define Command #1 : CommandHelloWorld
//
var cmd = Application.CreateCommand( "CommandHelloWorld" )
cmd.ScriptingName = "CommandHelloWorld" ;
cmd.Language = "JScript" ;
cmd.ReturnValue = false ;
cmd.Handler = "HelloWorld" ;
cmd.FileName = fileNameWithPath;
Application.AddCommand( cmd ) ;
//
// Define Command #2 : CommandSimple
//
cmd = Application.CreateCommand( "CommandSimple" )
cmd.ScriptingName = "CommandSimple" ;
cmd.Language = "JScript" ;
cmd.ReturnValue = true ;
cmd.Handler = "Simple" ;
cmd.FileName = fileNameWithPath;
// You must mention the arguments you want.
// The name is not important but must be unique
cmd.Arguments.Add("a")
cmd.Arguments.Add("b")
Application.AddCommand( cmd )
//
// Define Command #3 : CommandSimpleObjectArg
//
cmd = Application.CreateCommand( "CommandSimpleObjectArg" )
cmd.ScriptingName = "CommandSimpleObjectArg" ;
cmd.Language = "JScript" ;
cmd.ReturnValue = true ;
cmd.Handler = "SimpleObjectArg" ;
cmd.FileName = fileNameWithPath;
cmd.Arguments.AddObjectArgument("obj");
Application.AddCommand( cmd )
}
function DemoCommands()
{
// It is simple to execute a custom command, especially one
// like this with no return value or arguments.
// Will log "Hello World"
CommandHelloWorld() ;
// Will log "15"
logmessage( CommandSimple( 5, 10 ) );
// Will log "concat"
logmessage( CommandSimple( "con","cat" ) ) ;
newscene( null, false ) ;
var oSphere = ActiveSceneRoot.AddGeometry("Sphere", "NurbsSurface") ;
//Will log:
//INFO : "Name of the input object sphere"
//INFO : "grid"
logmessage( CommandSimpleObjectArg( oSphere ) ) ;
//Softimage can also turn an string to an object:
//INFO : "Name of the input object grid"
//INFO : "grid1"
logmessage( CommandSimpleObjectArg( "grid" ) ) ;
}
function CleanupCommands()
{
Application.RemoveCommand( "CommandHelloWorld" ) ;
Application.RemoveCommand( "CommandSimple" ) ;
Application.RemoveCommand( "CommandSimpleObjectArg" ) ;
} |
' -------------------------------------------------------------- ' ' This VBScript example demonstrates how to find a built-in ' (or native) Softimage command using its scripting name. ' ' -------------------------------------------------------------- ' Loop through the Softimage command collection looking for a name match for each c in Application.Commands if c.ScriptingName = "FreezeObj" then ' At this point, you could either... ' ...get its name to use elsewhere ... sScpName = c.Name ' ...use it to create a Command object... set oCmd = c ' ...or perform whatever action you want on it, like demonstrating ' the difference between the Name and ScriptingName properties Application.LogMessage "FreezeObj info......." & vbLf _ & vbTab & "Name = " & c.Name & vbLf _ & vbTab & "ScriptingName = " & c.ScriptingName end if next ' With the new command pointer, we can access command information Application.LogMessage oCmd.Name & ": Belongs to the " & oCmd.Category & " category/menu." ' Now that we know the command's full name, we can access the command using ' the name as the key in the command collection set oCommand = Application.Commands( sScpName ) Application.LogMessage oCommand.Name & ": " & oCommand.Description ' -------------------------------------------------------------------------- ' Output of above script: 'INFO : "FreezeObj info....... ' Name = Freeze Operator Stack ' ScriptingName = FreezeObj" 'INFO : "Freeze Operator Stack: Belongs to the Edit category/menu." 'INFO : "Freeze Operator Stack: Freeze all the operators of the selected object(s)" |
/* --------------------------------------------------------------
Hello World example, based on v1.5 workflow for defining a command
This JScript example creates and registers a custom
command and then demonstrates how you can find it in
the Softimage command collection using the Builtin property.
----------------------------------------------------------- */
// Start off with a clean slate
Application.RemoveCommand("Howdy");
// Get the factory (installation) path and use it to build the filename & path
var sFileName = InstallationPath( siUserPath ) + "\\Data\\Scripts\\HelloWorld.js";
// Create a standard hello world script file
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var fHWFile = fso.CreateTextFile( sFileName );
fHWFile.WriteLine( "function SayHi()" );
fHWFile.WriteLine( "{" );
fHWFile.WriteLine( "\tApplication.LogMessage( \"Hello, World!\" );" );
fHWFile.WriteLine( "}" );
fHWFile.Close();
// Add it to the command map in Softimage
var oCmd = Application.CreateCommand( "Howdy", siExportCategory );
oCmd.Description = "Display the traditional greeting";
oCmd.ScriptingName = "Howdy";
oCmd.Handler = "SayHi";
oCmd.FileName = sFileName;
oCmd.Language = "JScript";
Application.AddCommand( oCmd );
// Run it just to make sure it's working
oCmd.Execute();
// Now loop through the command collection and print the name and
// scripting name of each custom command
// (Tip: It is faster to use CommandCollection.Filter("Custom") to
// find all custom commands)
var eCmdList = new Enumerator( Application.Commands );
eCmdList.moveFirst();
var c;
for (; !eCmdList.atEnd(); eCmdList.moveNext() )
{
c = eCmdList.item();
if(!(c.Builtin))
{
LogMessage( c.Name + "(" + c.ScriptingName + ") is a custom command." );
}
}
// Restore everything back to normal
Application.RemoveCommand("Howdy");
fso.DeleteFile( sFileName, true );
// --------------------------------------------------------------
// Output of the above script is:
//
//INFO : "Hello, World!"
//Howdy();
//Followed by a list of all custom commands installed, including:
//INFO : "Howdy is a custom command." |