' **********************************
'
' This example shows how to add a custom command to an add-on package.
'
sPath = InstallationPath( siUserPath )
sCmdName = makeCusCmd()
' Create the add-on package object
set oAddOn = Application.CreateAddon
' Add the custom command to the add-on package
oAddOn.AddItem siScriptCmdAddonItemType, sCmdName
' Save the package in the Addons directory
sAddOnFileName = XSIUtils.BuildPath( sPath, "Addons", "myAddOn.xsiaddon" )
oAddOn.Save sAddOnFileName
' Remove the custom command and install it from the add-on package
if cleanUpCmd( sCmdName ) then
Application.InstallAddOn sAddOnFileName, siUserAddonPath
' Run it to make sure it works
set oInstalledCmd = Commands( sCmdName )
if TypeName( oInstalledCmd ) <> "Nothing" then
Application.LogMessage "Logged after installing from add-on:"
oInstalledCmd.Execute
' After we know it works, we can uninstall it
Application.UnInstallAddon sAddOnFileName
else
Application.LogMessage "Can't find command."
end if
end if
' **********************************
' Helper functions that take care of
' creating and removing the command.
function makeCusCmd()
' Start with a clean slate
Application.RemoveCommand "Howdy"
' Build the filename & path
sCmdFileName = XSIUtils.BuildPath( sPath, "Data", "Scripts", "HelloWorld.vbs" )
' Create a "hello world" script file
set fso = CreateObject( "Scripting.FileSystemObject" )
set fHWFile = fso.CreateTextFile( sCmdFileName )
fHWFile.WriteLine "function SayHi()"
fHWFile.WriteLine " "
fHWFile.WriteLine vbTab & "Application.LogMessage " & Chr(34) & "Hello, World!" & Chr(34)
fHWFile.WriteLine "end function"
fHWFile.Close
' Add it to the command map in Softimage
set oCmd = Application.CreateCommand( "Howdy", siNoCategory )
oCmd.Description = "Display the traditional greeting"
oCmd.ScriptingName = "Howdy"
oCmd.Handler = "SayHi"
oCmd.FileName = sCmdFileName
oCmd.Language = "VBScript"
Application.AddCommand oCmd
' Run it just to make sure it's working
Application.LogMessage "Logged from within makeCusCmd():"
oCmd.Execute
' Return the name of the new command
makeCusCmd = "Howdy"
Application.LogMessage "========================================"
end function
function cleanUpCmd( in_sCmd2Delete )
Application.RemoveCommand in_sCmd2Delete
if Err.Number <> 0 then
cleanUpCmd = false
else
cleanUpCmd = true
end if
end function
' ------------------------------------
' Output of above script:
'
'INFO : "Logged from within makeCusCmd():"
'INFO : "Hello, World!"
'Howdy
'INFO : "========================================"
'INFO : "Logged after installing from add-on:"
'INFO : "Hello, World!"
'Howdy |