Additional Topics > ENVI Extension Wizard

# ENVI Extension Wizard

The ENVI Extension Wizard allows you to create an IDL project to be used as a custom ENVI extension. Custom ENVI extensions appear in the Toolbox within the ENVI application.

The steps necessary to build an ENVI extension are:

1. Use the ENVI Extension Wizard to create an IDL project, along with a corresponding IDL `.pro` file containing the extension template code.
2. Edit the extension code to perform your desired actions when the extension is invoked. See the ENVI Help topic Writing and Deploying Toolbox Extensions for details.
3. Using either the Project menu, or the context menu in the Project Explorer, choose Build Project. This will compile all of the required IDL code, and create an IDL SAVE file in the chosen extension directory. See Building IDL Projects for more information.
4. Start up the ENVI application. Your new extension should appear in the Toolbox. Double-click your extension to execute your code.

Note: If you have already run ENVI in the same session, you should execute a `.RESET_SESSION` command before restarting ENVI, to ensure that your new extension is loaded.

## ENVI Extension Wizard Dialog

To display the ENVI Extension Wizard, either select File->New ENVI Extension, or right-click in the Project Explorer and select New ENVI Extension from the context menu. The following fields are displayed in the wizard:

### Project Name

The name of the IDL project that will contain the new extension. This project name must be unique. See Projects for details.

### Extension Name

The human-readable name of the extension. This is the name that will be displayed in the Extensions Toolbox within the ENVI application.

### IDL Procedure

The name of the IDL procedure to run when the extension is executed. This needs to be a valid IDL procedure name. This will also be used as the name of the `.pro` file that gets created.

### Extension Path

A string denoting the tree structure, under the Extensions folder, in which the Toolbox item will appear. If the Extension Path is empty, the item will be added directly to the end of the Extensions folder. Multiple subfolders may be specified by adding the '/' character between folder names (for example, "My Routines/Statistics"). If a folder does not currently exist, it will be created.

### Save File Location

The location where the IDL SAVE file should be created when the project is built (see Building IDL Projects). The ENVI application looks in three locations for extensions:

- The directory given by the ENVI_EXTENSIONS environment variable
- The install directory, Install_Dir/products/enviextensions
- The user's home directory, user_home/.idl/exelis/enviextensions

If left empty, this field is set to the user's home directory. After the IDL project has been created, you can go to the IDL Build Properties page to modify the SAVE file location.

## Customizing the ENVI Extension Code

After you run the ENVI Extension Wizard, a new IDL editor opens, containing the extension code. The extension name, IDL procedure name, and extension path are automatically added to the code.

By default, the extension file contains an "`_extensions_init`" procedure at the top, followed by the actual extension procedure. The extension procedure has a section of generic error-handling code, and then a line of code to retrieve the current ENVI application object. Finally, you should insert your custom extension code near the bottom of the file, after the IDL comment block marked "`Insert your ENVI Extension code here...`".

If you wish, you may modify the default extension template code that is inserted. To modify the template, open the Preferences dialog in the IDL Workbench. In the Preferences dialog, choose IDL >Templates, and edit the ENVIExtension template to contain your desired code. The following custom variables are available:

Variable | Description
--- | ---
${EXTENSION_NAME} | The ENVI Extension name from the Wizard
${PROCEDURE_NAME} | The IDL Procedure name from the Wizard
${EXTENSION_PATH} | The Extension Path value from the Wizard

In addition, you can also use any of the other IDL template variables, such as ${date}, ${time}, ${user}, or ${year}.

The extension can also accept an `event` argument that contains the UVALUE set during the call to ENVI::AddExtension.