SuperCharging AutoCAD

Mechanical
Desktop

Introduction to AutoCAD
Mechanical

3D Basics

Introduction to AutoCADl

Introduction to AutoLISP
Training

Intermediate
AutoLISP
Training

Refresher/Update for AutoCAD 2000-2002

Registration

Creating a User Defined Toolbar Button
In the last two Tip Sheets, we explored creating a Custom Toolbar and a Custom Toolbar Flyout in AutoCAD 2002.  This month will complete the series on Toolbar Customization by describing how to create a user defined button.  I will outline how to create a macro for a button, edit the button image and manage button icons.

First, you'll need a toolbar to contain your custom button.  See the  Custom Toolbar Tip Sheet for information on creating a toolbar. Now, right-click on any toolbar button and select
Customize… from the menu.

Next, left-click on the Commands tab to add buttons from the command button library. To add a custom button, left-click on User defined in the list of Categories and drag the User Defined Button to the desired location in the toolbar.  Next, right-click on the new button and select Properties from the menu.

This new button will automatically purge the drawing of all unused information.

Name: The text placed in field will be displayed as the  tool tip when you move your pointer over the button.

Description: The text in this field will be displayed in the status line as a help string when you pause your pointer over the button.

Macro associated with this button: The text in this field defines what actually happens when you select this button.

Here is what I have so far.

I think the Name and Description fields are pretty self-explanatory.  Let's explore the Macro field.

The PURGE command normally displays a dialog box.  To automate the process, we need to avoid the dialog box.  The "-" character placed in front of many commands forces command line input instead of dialog box input.

The first thing the
PURGE command asks is...

Enter type of unused objects to purge [Blocks/Dimstyles/LAyers/LTypes/Plotstyles/SHapes/textSTyles/Mlinestyles/All]:

ALL is in response to this prompt, indicating the ALL unused objects will be deleted.

Next, the PURGE command will ask for the names of the objects to delete.  The "*" is a wildcard that means all names.

The last prompt from
PURGE is

Verify each name to be purged? [Yes/No] <Y>:

NO is the response to this prompt, indicating that all object name will be deleted without verification.

Now, I'm not going to get carried away with a fancy image.  Besides, there is only so much detail you can see in an image.  I like to turn the Grid on  to help keep straight line straight.

I've used the Line tool to draw a red minus sign on my button.  Next, I left-click on the Save As… button, name the BMP file and locate it in a folder I keep for button icons.  This is an important step in managing the button icons.

Now I click on the
Close button to return to the Properties window.  Left-clicking on the Apply button applies the image to the new button.

The final step is to left-click on the Close button and try out the new Purge All button.

Sometimes I just want to purge the unused Blocks in the drawing.  Here is the code behind my
Purge All Blocks button.

I basically used the same code as in the Purge All button, but specified blocks instead of all.  I made the button icon by starting with the Make Block icon and adding a red minus sign.  I made sure to save this to my icon folder as well.

Managing Icon Images
One of the most frustrating things about using custom buttons when AutoCAD loses track of them.  When this happens, the custom icons are replaced with the dreaded Smiley face.

One way to avoid this is to specifically name and locate the button icons .  I keep all my button icons in one folder and include that folder in the AutoCAD File Search Path.

That's not all though.  Here is the toolbar code for two PURGE buttons created above.

[_Button("Purge All", "ICON6500.bmp", "ICON_16_BLANK")]^C^C-purge all * no
[_Button("Purge All Blocks", "ICON9169.bmp", "ICON_16_BLOCK")]^C^C-purge blocks * no

Notice the icon names specified in the code.  Check out  the Custom Toolbar Flyout Tip for information on  button codes.  These are not the names I specified, but ones that AutoCAD made up.  The icon files are placed in the current drawing folder when the button is made, so eventually, when I work on a drawing in a different folder, AutoCAD won't be able to find the icon files.  Voila, Smiley faces.

So, what I do is manually edit the *.MNS file and enter the file name that I specified.  Don't forget to backup your *.MNS files just like drawing files.  I've known a lot of people that accidentally reload their menu template file and destroy all their custom toolbars.  Here is what my button code looks like after inserting my bitmap names.

[_Button("Purge All", "purge_all.bmp", "purge_all.bmp")]^C^C-purge all * no
[_Button("Purge All Blocks", "purge_blocks.bmp", "purge_blocks.bmp")]^C^C-purge blocks * no

Creating a DLL File
A dynamic link library (DLL) is a collection of small programs or resources, any of which can be called when needed by a larger program that is running in the computer.

If you create dozens of toolbar buttons, you might want to investigate placing them in a DLL file.
  AutoCAD will automatically load and search a DLL file with the same name as a loaded partial menu.  See the Custom Menus Tip Sheet for information on creating partial menus.  Typically, you need to write a C program to place icon files in a DLL.  However, I've found a freeware program named ResourceHacker that not only allows you to create DLL files, it let's you extract icons from other DLL files.

So in my case, I've created a partial menu file named CINDY.MNU containing the toolbar described above.  Then, using ResourceHacker, I created a file name CINDY.DLL and added the PURGE_ALL.BMP file and PURGE_BLOCKS.BMP file.  Again, I've placed these files in a folder on the AutoCAD Support File Search Path so they will be found.

I hope you've enjoyed this small series on Toolbar Customization.  If you have any ideas for future Tip Sheets, please contact me at the link to the left.


Top of Page