AutoCAD

Toolbar templates

1 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.

 

Download the Lessons in Programming code. The file name is MAR02.exe.

 
Creating a toolbar template is simple. Once you have a template, you can quickly add toolbars later for your program's interface. However, don't use AutoCAD's Customize button in the Toolbars dialog box to make your toolbars. You must keep your menu system separate from AutoCAD's by creating your own partial toolbar menu files.

Here's how
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:
;;;TOOLBAR.MNL
(setq MYPATH c:/myprogram/)
(load (strcat MYPATH MYPROGRAM ))
(princ)

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).

Figure 1. Smiley faces indicate missing bitmaps.

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

 

;;;note:replace items in italic with your own names
***MENUGROUP=MYPROGRAM
***TOOLBARS
**TB_MY_PROGRAM
[_Toolbar(My Program ,_Floating,_Show,742,121,1)]
[_Button(Name1 ,image1.bmp ,image1.bmp )]^C ^C
[_Button(Name2 ,image2.bmp ,image2.bmp )]^C ^C
[_Button(Name3 ,image3.bmp ,image3.bmp )]^C ^C
[_Button(Name4 ,image4.bmp ,image4.bmp )]^C ^C
[_Flyout(Flyout1 ,image5.bmp ,image5.bmp , _OtherIcon,FLYOUT1.MYPROGRAM)]
**TB_FLYOUT1
**FLYOUT1
[_Toolbar(Flyout1 ,_Floating,_Show,742,121,1)]
[_Button(Name5 ,image5.bmp ,image5.bmp )]^C ^C
[_Button(Name6 ,image6.bmp ,image6.bmp )]^C ^C

 


AutoCAD Tips!

Lynn Allen

Autodesk Technical Evangelist Lynn Allen guides you through a different AutoCAD feature in every edition of her popular "Circles and Lines" tutorial series. For even more AutoCAD how-to, check out Lynn's quick tips in the Cadalyst Video Gallery. Subscribe to Cadalyst's Tips & Tricks Tuesdays free e-newsletter and we'll notify you every time a new video tip is available. All exclusively from Cadalyst!
Follow Lynn on Twitter Follow Lynn on Twitter


Latest News from Cadalyst Partners
Feed
Place your DWG File on a Diet   18 Jun, 2013

I received an email from blog reader Steve Roberts with a suggested tip topic on how to reduce the size and clean up DWG drawing files using four...More>>Read all Between the Lines blog posts>>

Feed
Tech Toys 360: Pro-Form Le Tour de France Bike   18 Jun, 2013

The greatest bike race in the world is held June 19 to July 21 this year. Celebrating its 100th year, the Tour de France sends riders through more...More>>Read more PTC Creo blog posts>>

Feed
Update 3 now available for Revit 2013 Products - Revit Clinic   18 Jun, 2013

...More>>Read more BIMbuilder blog posts>>

Feed
Nice Design—What Does It Feel Like?   17 Jun, 2013

...More>>Read more SolidWorks Blog posts>>

Feed
LiveMap: The Augmented Reality Motorcycle Helmet of the Future?   18 Jun, 2013

Philippe Starck once famously said that there should be no cars on the road—-only motorcycles. While some soccer moms may disagree, his theory...More>>Read more SolidSmack blog posts>>

Poll
How many years' experience do you have using CAD software?
Less than two years
2–5 years
6–10 years
11–20 years
21+ years
Submit Vote




FREE Resources for CAD, BIM, and PLM Users





Subscribe Cadalyst Newsletters