VBA Hints for Customizing AutoCAD (Hot Tip Harry AutoCAD Tutorial)1 Sep, 2008 By: Bill Kramer
Harry shares some Visual Basic favorites as well as this month's top tip for making custom linetype.
Tip 3006: Script Manager
Let's start with the VBA tips. Script Manager by Ed Jobe is a VBA-based utility to manage and run script files in a custom folder. Before you can use this tip, you will need to load it into AutoCAD's VBA editor (use VBAman to load the file, then VBAide to edit it) and change the starting and personal folder paths. Module 1 contains a brief description of the edits required to make this work for your setup. After you make the needed changes, this routine, which is launched by LISP macros in supplied examples, will present a dialog box of the script files available to run. You can edit, rename, run, or delete existing scripts or create a new script to run in Notepad. This utility is a great example for those just learning VBA, and it's quite useful if you have a library of scripts to manage.
Tip 3007: Integrated Database
Integrated Database is a rather complex VBA example program for producing a material list with an integrated Microsoft Access database. The tip serves more as a useful example for study by VBA students than as a utility you can put right to work. Supplied by Andrew Maser and written according to in-house standards at McBride Engineering, it demonstrates quite a few VBA features, such as how to interface with an Access database and how to automate the creation of a bill of materials for cost estimation.
Tip 3008: Rename Layouts
Rename Layouts from James Sturgess is a neat little AutoLISP routine for naming layouts based on a text or an attribute selection within a drawing. After you load the LISP code, select the layout tab you want to modify to make it current and type NLay. You will be asked to select a text or an attribute object. The layout is renamed to the value in the text string. Quick and simple gets the job done — cool idea!
Tip 3009: Duct Transition
Shawn Evjen submitted Duct Transition, an expert drafting utility that skillfully creates the transition element graphic between two different duct sizes given just a few selections. Load the LISP code and type Duct_Trans when you are ready to draw a transition section. First, select one edge of the existing duct (end point). Next, pick a point toward the opposite side (perpendicular to the duct-run direction). Last, enter the initial duct size (default is the distance between the two points just described) and the ending duct size. A transitional element (drawn using polylines on the current layer) is the automatic result. This programming effort was time well spent; thanks for sharing!
Tip 3010: AIA Standard Layers
Michael Stachulak provided AIA Standard Layers, a must-have utility for architects who create all the layers needed for the American Institute of Architects standards according to the 1997 AIA CAD Layer Guidelines. The utility creates a long list of layers with linetypes and colors. Layers are created only if they don't already exist in the drawing, thus the utility will not interfere with the use of prototype drawings. To use this utility, simply load the LISP code and type AIALayers2009 at the AutoCAD Command line. (Note that a separate download file, AIALayers.LSP, is included for pre-AutoCAD 2009 compatibility.)
Tip 3011: Create Custom Linetype
This month's top tip by Ron Perez is Create Custom Linetype, which automates the steps needed to make a custom linetype with embedded characters. Load the LISP code and type MakeLT to start it. You will be asked to supply a string to be embedded in the linetype. Type in the characters and select Enter. A temporary linetype file definition is created and loaded into the current drawing. All you need to do now is relate it to a layer name, and it is ready to go. This is a nice timesaver for those who make custom linetypes, and it's well deserving of this month's top tip prize!
Thanks to all the tipsters. If you have a tip you'd like to contribute, Harry has some very nice T-shirts to trade for your code. Maybe your code will be selected as a top tip — an honor not everyone can boast — and Harry will throw in an extra $100. Until month, keep on programmin'.
Join the Hot Tip Harry Challenge
Harry needs your tips! Do you have an original routine written in VBA, Visual LISP, or even ObjectARX for AutoCAD customization? Send it in, with all the source code, to firstname.lastname@example.org. Your tip may be needed by others now, so don't delay!
Subscribe to Harry's Code Class
Cadalyst's Hot Tip Harry helps programmers and programmer wannabes learn the ins and outs of AutoCAD customization in his monthly e-newsletter, Harry's Code Class. Subscribe to Harry's Code Class today and start building your programming expertise.
Hot Tip Harry Discussion Forums
Harry is standing by online to aid AutoCAD users and programmers. Cadalyst's Hot Tip Harry -- Help! Discussion Forum offers assistance with AutoCAD programming and customization problems. Hot Tip Harry -- Requests Discussion Forum can help you locate a specific LISP or VBA routine for AutoCAD. Participation in Cadalyst Discussion Forums requires registration, but it's free.
Get Your Weekly Fix of AutoCAD Tips
Cadalyst's Tips & Tools Weekly e-newsletter mails each Monday, delivering AutoCAD tips by readers for readers -- all reviewed by Cadalyst's volunteer Tip Patrol. Plus, you'll receive a rundown of new online CAD resources, deals and freebies, new CAD-related hardware and software products, and more. View the Cadalyst Tips & Tools Weekly archives and subscribe today!
AutoCAD Users: Check out Cadalyst Tips & Tricks Tuesdays
All it takes is a minute or two, and you could be off to more productive use of AutoCAD. Cadalyst announces Tips & Tricks Tuesdays with worldwide AutoCAD Technical Evangelist Lynn Allen. Each Tuesday, Lynn and Cadalyst bring a new, super-quick tip to the Cadalyst Video Gallery. Subscribe to Tips & Tricks Tuesdays and receive an e-mail notification every time a new tip goes live in the Cadalyst Video Gallery.
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 free Tips & Tools Weekly e-newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!