Toolbar templates1 Mar, 2002 By: Barry Bowen
Add custom toolbars to your AutoLISP program interfaces.
Toolbars are an essential part of any custom program or application you write. They provide an efficient and friendly interface for users to access your program. They also keep your program separate from AutoCAD's menus.
To get started, use a text editor such as Notepad to create a new file named TOOLBAR.MNS in your programming folder. This serves as the toolbar template for all the partial toolbar menus you create. Note that we're using the MNS extension, not the MNU extension.
In the text editor, type the lines in the box below into the open file, then save it for use later. Replace the items in italic with your own. See the next section for details on how to create your own custom toolbar icons.
Next, use the text editor to create a file that loads an AutoLISP application
menu. Save this file as TOOLBAR.MNL. It contains the following lines:
(setq MYPATH c:/myprogram/)
(load (strcat MYPATH MYPROGRAM ))
When AutoCAD loads the partial menu toolbar, the MNL file of the same name loads and executes, setting the path (MYPATH) and loading the AutoLISP program (MYPROGRAM).
Create your icons
You can create image bitmaps for the toolbar icons in the AutoCAD toolbar editor or in other programs such as Microsoft Paint. Small bitmap images measure 1615 pixels in size, which AutoCAD 2000 stretches when Large buttons are on. Be sure to store the image files in the same folder as the menu file and add the path in AutoCAD. Loading the menu file without letting AutoCAD know where the bitmap images are results in a toolbar with smiley faces, as shown in figure 1.
I see smiley faces
Smiling faces in your toolbar indicate that AutoCAD could not find the icon bitmaps. To correct this, make sure you added the path to the bitmaps. In AutoCAD, select Tools | Options from the pull-down menu. On the File tab click the plus sign (+) before the Support File Search Path. Click the Add button, then Browse to locate the folder that holds the program bitmaps.
Select OK, then close the dialog box and AutoCAD. Open Windows Explorer and locate the folder where you stored the menu and image files. Delete the MNC and the MNR menu files. When you start AutoCAD again, the toolbar icons should appear correctly.
Because of the limited space for this article, I have included a sample program and toolbar to further illustrate how to apply the toolbar template to a sample custom program. You can download all the related code.
Code for Toolbar.MNS
In her easy-to-follow, friendly style, long-time Cadalyst contributing editor Lynn Allen guides you through a new feature or time-saving trick in every episode of her popular AutoCAD Video Tips. Subscribe to the free Cadalyst Video Picks newsletter, and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!