Addon
v3.5
The Addon object lets you package, install, and uninstall
add-ons through scripting. An add-on is a collection of plug-in
items such as toolbars, custom commands, and layouts that can be
easily packaged and deployed to other computers.
Note: The Addon object gives you precise control over the contents
of an .xsiaddon file, but requires that you add each file
individually. The PackageAddon command provides a
easier way to build .xsiaddon files.
| Application | Categories | DefaultInstallationPath | FullName
![]() |
| Help | Name ![]() |
NestedObjects | Origin |
| OriginPath | Parent | SubDirectory | Type ![]() |
/* --------------------------------------------------------------
This example creates and registers a custom
command and then shows how you can package it
as an add-on through scripting.
----------------------------------------------------------------- */
/*
PART ONE: SET UP THE COMMAND
*/
// Start off with a clean slate
NewScene( null, false );
Application.RemoveCommand( "Howdy" );
// Get the factory (installation) path and use it to build the filename and path
var sPath = InstallationPath( siUserPath );
var sCmdFileName = XSIUtils.BuildPath( sPath, "Data", "Scripts", "HelloWorld.js" );
// Create a "hello world" script file
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var fHWFile = fso.CreateTextFile( sCmdFileName );
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 = sCmdFileName;
oCmd.Language = "JScript";
Application.AddCommand( oCmd );
// Run it make sure it works
oCmd.Execute();
/*
PART TWO: PACKAGE IT AS AN ADD-ON
*/
// Set up the add-on package object
var oAddOn = Application.CreateAddon();
// Add the new command to the add-on package
oAddOn.AddItem( siScriptCmdAddonItemType, oCmd );
// Set the default installation path and subdirectory for installation
oAddOn.DefaultInstallationPath = siUserAddonPath;
oAddOn.SubDirectory = "HiyaProject";
// Save the .xsiaddon file to disk
var sAddOnFileName = XSIUtils.BuildPath( sPath, "myAddOn.xsiaddon" );
oAddOn.Save( sAddOnFileName );
// Remove the custom command we created and then install the add-on
Application.RemoveCommand("Howdy");
fso.DeleteFile( sCmdFileName, true );
oCmd = null;
oAddOn = null;
Application.InstallAddon( sAddOnFileName, siUserAddonPath );
// Run the command to make sure it still works after we removed it and
// then reinstalled it from our new add-on package
Commands( "Howdy" ).Execute();
// Clean up and remove the add-on package
sInstalledAddOnFileName = XSIUtils.BuildPath( InstallationPath( siUserAddonPath ), "InstalledAddons", "myAddOn.xsiaddon" );
Application.UninstallAddon( sInstalledAddOnFileName );
// --------------------------------------------------------------
// Output of the above script is:
//
//INFO : "Hello, World!"
//Howdy(null);
//INFO : "Hello, World!"
//Howdy(null);
|