Tips from Our Readers -- April 2007 (Hot Tip Harry AutoCAD Tutorial)

9 Apr, 2007 By: Bill Kramer

Many of this month's tips are related to layer control.

Download code for this and all articles. Look for APR07.exe in Get the Code. Downloads are free and are provided "as is" without warranty or support.
Tips are tested using AutoCAD 2007, unless otherwise noted. By submitting code to Cadalyst, you grant Cadalyst the right to print and distribute your code in print, digitally and by other means. Cadalyst and individual authors retain all rights to the code, and it is not to be used for commercial purposes.
Important note: Be sure your submission contains all elements required for it to run independently using AutoCAD 2006. Tips that are missing functions or other necessary elements will not be considered.
Join the Hot Tip Harry Challenge
Calling all tip writers! The Hot Tip Harry Challenge is under way for 2007 and is sponsored by Autodesk.
Share your hot tips and tricks to win an official Cadalyst t-shirt and a chance to win a trip to Autodesk University 2007 and cash prizes. Click here for more details.
E-mail those tips and tricks to
For More AutoCAD Tips More Often: Check out Cadalyst's free Tips & Tools Weekly e-newsletter. View the archives and subscribe today!
Join the Hot Tip Harry Challenge
Calling all tip writers! The Hot Tip Harry Challenge is under way for 2007 and is sponsored by Autodesk. Share your hot tips and tricks for a chance to win a trip to Autodesk University 2007, cash prizes and an official Cadalyst t-shirt. For more details, click here.

Drawing standards are important, and everyone focuses on layers at one point or another. Because AutoCAD lets you define any number of layers with a variety of properties, it's not surprising that virtually all AutoCAD users have created their own layering standards at one time or another. Harry reports that many of this month's tips are related to layer control and that some heavy coding bears study, even by the most advanced programmers. Let's take a look to see if anything is useful to you.

Thaw All Layers in a Drawing (Tip #2196) from Brian Benton is a command-sequence macro in which multiple AutoCAD commands are condensed into a single two-letter command. In this case, the command sequence thaws all the layers in the current drawing by just typing LL after the LISP code has been loaded into AutoCAD. Nothing fancy here, just raw productivity.

Force Blocks to Specific Layers (Tip #2197) from Peter Jamtgaard is a magnificent set of functions that forces your block insertions to follow a specific layer standard. Two files in addition to a LISP file are included with this tip. Place the associated DCL and CSV files in a folder searched by AutoCAD. When loaded, a reactor is established that checks for Insert and MInsert command execution completion. This reactor function looks at the name of the inserted block and checks it against a list of standard layer assignments (stored in the CSV file). If the block isn't in the list of known blocks, a dialog box opens for you to set up the block-layer relationship. You also can edit the block-layer relationships by entering the command BlockLayer at the Command prompt after the LISP code has been loaded. This tip involves a lot of complex programming, reading and writing a CSV file, dialog box manipulation and reactors. As a result of all the cool coding, this tip clearly deserves to be this month's top tip. Great work, Peter!

Road Layout (Tip #2198) from Mark LaBell is a great example of a command sequence that gets a lot done with minimal input. In this case, the routine creates the offset lines associated with detailing a roadway with sidewalk. After drawing the road centerline (as a polyline), load the LISP code and type ROAD. You are asked to select the centerline and then supply parameters for the distances to the various edges. The offset and layer commands take over from there and turn your centerline into a series of offsets representing the roadway, sidewalks and edges.

Paper Space Manager (Tip #2199) by Leonid Nemirovsky is a subset of his more elaborate tool library. The paper space utility set consists of two LISP files along with a DCL file and block drawing that need to be placed in the search path of AutoCAD. After loading the PSP1.LSP and RV.LSP files into AutoCAD, type PSP1 to activate the paper space utility. A dialog box opens for you to enter details about the paper space view to be constructed. When the paper space view is created, a copy of the PSP1 block is included. This block contains attributes about the detail view. You can view and edit the attributes using normal AutoCAD attribute edit procedures. When you need to revise a detail, type RV and then select the view in paper space you want to adjust. Model space is immediately restored; you are zoomed into the area from which the paper space detail was created. This utility is just a subset of the larger utility library. A more robust version can be downloaded from Leonid's Web site. Thanks, and a tip of the hat to Leonid for another wonderful tip!

Aligned Multiple Line Text (Tip #2200) by David Harrington lets you to pick an object that you want mtext to align with. Load the LISP code and type ADX at the command line. You are asked to select an object in the drawing. Pick a line and the Mtext command starts with the angle of the text inserted to match the angle of the line selected. Now type in the text and press the OK button in the Mtext dialog when finished. The routine asks you to select another object. When selected, the same text is placed along the newly selected object. This tip is a great productivity utility for labeling map lines and similar features in a drawing.

Move Hatches and Images to the Back (Tip #2201) by Scott Wilcox automates the use of the DWGOrder command in AutoCAD to move all crosshatches and images to the back of the drawing order. By moving those objects to the back, other drawing elements appear drawn last or on top. To use this tip, just load the LISP file and type Hatchback at the AutoCAD command prompt; the rest is automatic, just like it should be!

Fast Zoom to the Limits (Tip #2202) by Lee Colville uses the extended features of Visual LISP to create a faster zoom macro to the limits of the current drawing. Equivalent to the Zoom All command in AutoCAD, this command function simply runs faster and bypasses the zooming visual effect and sometimes clunky command interface. Load the LISP code into AutoCAD and type Autolimits at the Command line to run. This function is obviously intended for use as a menu macro call and should be included in your own custom LISP library. Thanks, Lee, for a great programming improvement!

Disappearing Objects (Tip #2203) by Greg Silva is a set of command functions used to control the visibility of objects in a drawing. Inside AutoCAD, each drawing object has a visibility property that is either true or false. When false, the object is not visible. Greg's command functions take advantage of that property, and they are available after loading the LISP code. The command functions include CLR to set a currently visible object invisible, AO to turn all objects to visible, HMO to report the number of visible and invisible objects to the AutoCAD text screen and RO to reverse the visible and invisible flags so that all objects that were visible are now invisible and all previously invisible objects are now visible. It works just like magic! It's lots of fun to play with and is extremely useful when building a presentation around a complex electronic drawing. This program demonstrates the power of Visual LISP.

Keep Programmin'
That completes this month's tip sheet -- another great set of programming tips from your fellow AutoCAD users. Do you have something that you've written and want to share with everyone? Harry pays well for those that are used, check out the details and send in your tip. It doesn't have to be a programming masterpiece -- there is beauty in simplicity and elegance in usefulness. Until next time, keep on programmin'.

About the Author: Bill Kramer

More News and Resources from Cadalyst Partners

For Mold Designers! Cadalyst has an area of our site focused on technologies and resources specific to the mold design professional. Sponsored by Siemens NX.  Visit the Equipped Mold Designer here!

For Architects! Cadalyst has an area of our site focused on technologies and resources specific to the building design professional. Sponsored by HP.  Visit the Equipped Architect here!