X
7210

How to Add a New Button to the ENVI Menu


The following article shows how to add a custom button to a submenu under the ENVI main menu. The sample program below adds a custom menu called 'My Tools' and button called 'Get Some File Info' to the Basic Tools > Preprocessing menu:

Basic Tools > Preprocessing > My Tools > Get Some File Info

Clicking on this button will activate a dialog box prompting the user to select an image file. Some error handling code statements can catch invalid files. Basic file information will be output to the Workbench console tab and will contain the following:

- File dimensions in ENVI 'dims' format
- The number of samples in the image file
- The number of lines in the image file
- The number of bands in the image file

This file can be copied directly into the ENVI/IDL Workbench. Once saved and compiled it should be placed in the ENVI 'save_add' directory. Assuming a default installation on Windows XP this location would be:
C:\Program Files\ITT\IDL\IDLxx\products\envixx\save_add

The ENVI_DEFINE_MENU_BUTTON procedure is used to add menu items (buttons) to the ENVI menu system. This is accomplished through a *.pro file or *.sav file placed in the save_add directory. The syntax requires that the *.pro or *.sav file must contain the name of the main procedure followed by '_define_buttons'.
For example, if the file in the save_add directory is called 'Get_Some_FileInfo.pro' then the procedure to define the button will be 'Get_Some_FileInfo_define_buttons.pro'.

The button definition procedure allows for a variety of custom menu locations and button definitions in ENVI. For more options please see the ENVI_DEFINE_MENU_BUTTON procedure in the ENVI Help system.

The following example program shows the main procedure and the button definition procedure for a program called 'Get_Some_FileInfo':

; ++++++++++++++++++++++++++++
pro Get_Some_FileInfo_Define_Buttons,buttonInfo,buttonInfo

; Modified to incorporate access via main menu
; Error catch mechanism
compile_opt idl2

; Set up the button so the program can be used from the ENVI menu
envi_define_menu_button, buttonInfo, value = 'My Tools', $
/menu, ref_value = 'Preprocessing', ref_index=0, position = 'after'

envi_define_menu_button, buttonInfo, value = 'Get Some File Info', $
uvalue = 'Get Some File Info', event_pro = 'Get_Some_FileInfo', $
ref_value = 'My Tools', position = 'last'

END

; ++++++++++++++++++++++++++++

pro Get_Some_FileInfo,event

compile_opt idl2

;Get image file
file_name=dialog_pickfile(title='Input Image File')
if (file_name eq '') then
return

;Open the file
envi_open_file, file_name, r_fid=fid
if (fid eq -1) then return

;Query the file and get some basic information
envi_file_query, fid, dims=dims, ns=ns, nl=nl, nb=nb, $
xstart=xstart, ystart=ystart

print, ' *** File Info ***"
print, 'File dimensions are:', dims
print, 'Number of samples (x):', ns
print, 'Number of lines (y):', nl
print, 'Number of bands:', nb

END