## InstallAddon

### Description

Installs an add-on file in Softimage. To execute this command, you need to have an add-on file saved on disk. Add-on files for Softimage have the .xsiaddon extension. Add-on files contain settings for the layout of Softimage, toolbars, keymaps, custom commands, etc.
This command is the scripting equivalent of launching the Install option from the File > Addon location in the main menu.

### Scripting Syntax

    InstallAddon( FileName, [InstallPath] );

### Parameters

Parameter | Type | Description
--- | --- | ---
FileName | String | The .xsiaddon file.
InstallPath | siInstallationPath | Use this to specify a installation location for the addon. siUserAddonPath and siWorkgroupAddonPath are the recommended values. If siUnknownPath is specified then the add-on will be installed at the default location specified inside the add-on file (see Addon.DefaultInstallationPath). Default Value: 7 (siUnknownPath)

### Examples

#### VBScript Example

    '---------------------------------------------------------

    ' This script demonstrates how to install and uninstall

    ' user add-ons and factory add-ons.

    '---------------------------------------------------------

    ' Get the filename of an available add-on file, and install it, in the user add-on path.

    myAddonFile = createAddonForDemo( siUserPath )

    Application.LogMessage "Installing: " & myAddonFile

    InstallAddon myAddonFile, siUserAddonPath

    ' Now find the installed file.

    myAddonFile = XSIUtils.BuildPath( Application.InstallationPath(siUserAddonPath), "DemoAddon.xsiaddon" )

    Application.LogMessage "Uninstalling: " & myAddonFile

    UnInstallAddon myAddonFile

    killCmdForDemo		' clean up the command that was loaded from the add-on

    ' Now re-install it to the AddonPath.

    myAddonFile = createAddonForDemo( siFactoryPath )

    Application.LogMessage "Installing: " & myAddonFile

    InstallAddon myAddonFile, siAddonPath

    ' Now uninstall the add-on (again).

    myAddonFile = XSIUtils.BuildPath( Application.InstallationPath(siAddonPath), "DemoAddon.xsiaddon" )

    Application.LogMessage "Uninstalling: " & myAddonFile

    UnInstallAddon myAddonFile

    killCmdForDemo		' the plug-in is not automatically unloaded when the add-on is uninstalled

    '---------------------------------------------------------

    ' Output from this script:

    'INFO : "Installing: <UserPath>\Addons\DemoAddon.xsiaddon"

    'INFO : "Uninstalling: <UserPath>\Addons\DemoAddon.xsiaddon"

    'INFO : "Installing: <FactoryPath>\Addons\DemoAddon.xsiaddon"

    'INFO : "Uninstalling: <FactoryPath>\Addons\InstalledAddons\DemoAddon.xsiaddon"

    '---------------------------------------------------------

    ' 	*** Helper functions ***

    '

    ' Create an add-on package on the fly

    function createAddonForDemo( in_Where )

    	dim l_AddonFile, l_PluginFile, l_AddonObj

    	l_AddonFile = GetAddonFileLocation( in_Where )

    	l_PluginFile = createCmdForDemo()

    	Set l_AddonObj = Application.CreateAddon()

    	l_AddonObj.AddItem siPluginAddonItemType, l_PluginFile

    	l_AddonObj.Save l_AddonFile

    	' Now that it's in the .xsiaddon file, kill the source

    	killCmdForDemo

    	createAddonForDemo = l_AddonFile

    end function

    ' Validate the add-on file location

    function GetAddonFileLocation( in_Where )

    	dim l_folderLocation, l_fso

    	If in_Where = siUserPath Then

    		l_folderLocation = Application.InstallationPath( siUserAddonPath )

    	Else

    		l_folderLocation = Application.InstallationPath( siAddonPath )

    	End If

    	Set l_fso = CreateObject( "Scripting.FileSystemObject" )

    	' Make sure the Addons folder exists

    	If Not l_fso.FolderExists(l_folderLocation) Then

    		l_fso.CreateFolder l_folderLocation

    	End If

    	GetAddonFileLocation = XSIUtils.BuildPath( l_folderLocation, "DemoAddon.xsiaddon" )

    end function

    ' Create the self-installing command plug-in on disk and load it

    function createCmdForDemo()

    	dim l_fileLocation, l_fso, l_ts

    	l_fileLocation = XSIUtils.BuildPath( Application.InstallationPath(siUserPath), _

    		"Application", "Plugins", "VBSCmdForAddonsDemoPlugin.vbs" )

    	Set l_fso = CreateObject( "Scripting.FileSystemObject" )

    	Set l_ts = l_fso.CreateTextFile( l_fileLocation )

    	l_ts.Write writeCmdImpl()

    	l_ts.Close

    	Application.LoadPlugin l_fileLocation

    	createCmdForDemo = l_fileLocation

    end function

    ' Supply the implementation of the self-installing command plug-in

    function writeCmdImpl()

    	writeCmdImpl = "function XSILoadPlugin( in_reg )" & vbCrLf _

    	& vbTab & "in_reg.Author = " & Chr(34) & "InstallAddonDemo" & Chr(34) & vbCrLf _

    	& vbTab & "in_reg.Name = " & Chr(34) & "VBSCmdForAddonsDemoPlugin" & Chr(34) & vbCrLf _

    	& vbTab & "in_reg.Major = 1" & vbCrLf _

    	& vbTab & "in_reg.Minor = 0" & vbCrLf _

    	& "" & vbCrLf _

    	& vbTab & "in_reg.RegisterCommand " & Chr(34) & "VBSCmdForAddonsDemo" & Chr(34) & ", " & Chr(34) & "VBSCmdForAddonsDemo" & Chr(34) & vbCrLf _

    	& vbTab & "XSILoadPlugin = True" & vbCrLf _

    	& "end function" & vbCrLf _

    	& "" & vbCrLf _

    	& "function VBSCmdForAddonsDemo_Init( in_ctxt )" & vbCrLf _

    	& vbTab & "Set oCmd = in_ctxt.Source" & vbCrLf _

    	& vbTab & "oCmd.Description = " & Chr(34) & "'Hello World' command for demonstration" & Chr(34) & vbCrLf _

    	& vbTab & "oCmd.ReturnValue = False" & vbCrLf _

    	& vbTab & "VBSCmdForAddonsDemo_Init = True" & vbCrLf _

    	& "end function" & vbCrLf _

    	& "" & vbCrLf _

    	& "function VBSCmdForAddonsDemo_Execute(  )" & vbCrLf _

    	& vbTab & "Application.LogMessage " & Chr(34) & "Hello, World!" & Chr(34) & ", siInfo" & vbCrLf _

    	& vbTab & "VBSCmdForAddonsDemo_Execute = True" & vbCrLf _

    	& "end function"

    end function

    ' Remove the self-installing command plug-in (and delete from disk)

    sub killCmdForDemo()

    	For Each p In Application.Plugins

    		If p.Name = "VBSCmdForAddonsDemoPlugin" Then

    			Application.UnloadPlugin p.Filename, true

    			Exit For

    		End If

    	Next

    end sub

### See Also

UnInstallAddon XSIApplication.InstallAddon XSIApplication.UnInstallAddon Addon Plugin