PluginRegistrar.RegisterCommand

説明

頻繁に使用するカスタムコマンドを Softimage に登録します。別のコマンドと名前が競合する場合は、コマンドは登録されません。

注:名前とスクリプト名の両方を一意の値にすることをお勧めします。

スクリプト 構文

oReturn = PluginRegistrar.RegisterCommand( Name, [ScriptName] );

戻り値

PluginItem

パラメータ

パラメータ タイプ 詳細
Name String 登録するカスタムコマンドの名前。同じ名前がスクリプト名として使用されている場合(推奨)、名前を文字から開始し、英数字とアンダースコア(_)記号のみを使用する必要があります。

コマンド名は、コマンドのコールバック関数(ExecuteInitなど)の名前を付ける場合に使用されますたとえば、"MyCommand"という名前のコマンドの Execute コールバックは"MyCommand_Execute"という名前になります。コマンド名にスペースが含まれている場合("My Simple Command"など)は、コールバック関数名でスペースを削除します("MySimpleCommand_Init"や"MySimpleCommand_Execute"など)。

コマンド名は、Softimage ユーザインターフェイスにも表示されます。また、XSIApplication.Commandsによって戻されるCommandCollectionのコマンドの名前でもあります。さらに、Menu.AddCommandItemを呼び出すときに使用する名前でもあります。

コマンド名は一意である必要があります。名前の重複を避けるために、会社名またはプラグイン名に基づくプレフィックス("ACME_TornadoKit_Apply"など)を使用することをお勧めします。
ScriptName String コマンドのCommand.ScriptingName

ユーザがスクリプトでコマンドを簡単に実行できるようにするため、スクリプト名は文字から開始するようにする必要があります。以降に続く文字は、英字、数字、アンダースコア(_)のいずれも使用できます。

JScript の例

/*--------------------------------------------------------------------
        This example shows how to register and implement a custom command 
        When not specified, the Name argument is also used as the 
        command's scripting name. 
        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  XSILoadPlugin( in_reg )
{
        in_reg.Author = "Softimage Co."; 
        in_reg.Name = "PluginRegistrar.RegisterCommand Example";
        in_reg.Major = 1;
        in_reg.Minor = 0;
        // register the ABC command plug-in item
        in_reg.RegisterCommand("ABCCommand", "ABC");
        return true;
} 
// initialize the ABC command arguments
function  ABCCommand_Init( in_ctxt )
{
        var cmd = in_ctxt.Source;
        cmd.Arguments.Add("argument0");
        return true;
}
//function handler for the ABC command
function  ABCCommand_Execute( in_arg )
{
        Application.LogMessage("ABC command has been executed with argument: " + in_arg);
}
//--------------------------------------------------------------------
// Code to bootstrap example into system
//--------------------------------------------------------------------
function ExampleSourceCode()
{
        return "// XSISDK Doc Example\n" +
                ABCCommand_Init.toString() + "\n" + 
                ABCCommand_Execute.toString() + "\n" + 
                XSILoadPlugin.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             = "ExPluginRegistrarRegisterCommand";
        var ex_subfolder        = "Plugins";
        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,
                "Application",
                ex_subfolder,
                ex_name+ex_langsuffix );
        if (!fso.FileExists(filename))
        {
                var f = fso.CreateTextFile ( filename );
                f.write( ExampleSourceCode() );
                f.close();
                Application.LoadPlugin(filename);       
        }
}

関連項目

Plugin.Items Definition Callbacks for Commands