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
Autodesk Gallery Powers of Design Exhibit: 10**14 The Solar System   21 May, 2013

"The fireball that we rode was moving  But now we've got a new machine  Yeah Yeah Yeah Yeah the freaks said  Man those cats can really...More>>Read more It's Alive in the Lab blog posts>>

Feed
Webcast Replay: Flexible Design with PTC Creo   20 May, 2013

If you’re already familiar with Pro/ENGINEER, you’ll find PTC Creo familiar and intuitive in many ways, especially with the newly added PTC Creo...More>>Read more PTC Creo blog posts>>

Feed
Autodesk Revit Server 2014 - Now available for subscription customer download   20 May, 2013

Collaborate...coordinated... seamlessly... integrated...team...Wow...sounds awesome. Know anyone using...More>>Read more BIMbuilder blog posts>>

Feed
Discover and Fix Your Vibration Vulnerability with SolidWorks Simulation   17 May, 2013

When I go biking during the summer, I rely on the frame of my bicycle to withstand stresses such as vibration and impact. As I speed down the trail,...More>>Read more SolidWorks Blog posts>>

Feed
British Engineering in Effect. Flat-pack Truck Design for Developing Countries.   20 May, 2013

Imagine a crate of trucks that can be shipped on-site, built within a day, then sent to the four corners of the country delivering food, people,...More>>Read more SolidSmack blog posts>>

Poll
What type of input device (besides the keyboard) do you use at your primary CAD workstation?
Standard mouse
Trackball mouse
Programmable mouse
3D navigation device
Pen/tablet
Multiple devices
Submit Vote




Considering Wide Format Printing Solutions?
Four FREE White Papers Available:






Subscribe Cadalyst Newsletters