Building IDL Example Macros
Below are two examples that illustrate how a macro is created in IDL. The first example below is a UNIX-only example; the second example will work on either Microsoft Windows or UNIX.
Creating a Macro to Call a Text Editor in IDL for UNIX
On UNIX platforms, you can create a macro to open a file that is currently open in the IDL Editor in another editor, such as emacs or vi. Use the following procedure to create the macro:
- Select Macros ® Edit menu to bring up the Edit Macros dialog box.
- Complete the following fields in the Edit Macros dialog:
- Enter "Edit in emacs" in the Name field.
- Enter "emacs" in the Label field.
- Leave the Bitmap field blank. This macro will appear only in the Macros menu.
- Leave the Status bar text field blank. This value is used only when a toolbar button is present.
- Leave the Tip text field blank. This value is used only when a toolbar button is present.
- Enter the following in the IDL command field (notice that we are using the %L and %P command stream substitutions):
- Select the Menu checkbox to specify whether the macro will appear in the Macros menu.
- Create the new macro by clicking the Add button. The new emacs macro is added to the Macros menu.
To use this new macro, open the desired file in the IDL editor, then select emacs from the Macros menu.
To add a macro for editing in vi, repeat the above steps, but enter the following in the IDL command field:
Change Working Directory Macro
The following macro will select and change your current working directory. The steps below describe the fields of the Macros dialog on a Microsoft Windows system, but the macro will work equally well on a UNIX system.
First we will create a .pro file in IDL which will display a platform-specific directory-selection dialog.
- From the IDLDE, open a new IDL Editor window by selecting File ® New ® Editor.
- Type (or copy) the following lines of code into the new Editor window to form a program:
- Save the file as
cd_test.pro in a directory included in IDL's path. (The file must be in IDL's path so that IDL will find it automatically when the command cd_test is executed by the macro we will create.)
- Select Macros ® Edit menu to bring up the Edit Macros dialog box.
- Click Add to create a new macro. Enter "Change Directories" as the macro name.
- Complete the following fields in the Edit Macros dialog:
- Enter "cd_test" in the IDL command field.
- Enter "Change Directories" in the Menu item name field.
- Leave the Toolbar bitmap file field blank. This macro will appear only in the Macros menu.
- Leave the Tooltip text field blank. This value is used only when a toolbar button is present.
- Leave the Status bar text field blank. This value is used only when a toolbar button is present.
To use the new macro, select "Change Directories" from the Macros menu.