Tips from our Readers1 Jun, 2004 By: Bill Kramer
Routines to help you handle layers, change colors, and more.
STILL WEARING HIS FEDORA and overcoat, Harry plopped down in a chair and exclaimed, "You'd think after 20 years of this we'd figure out a single good way to handle layers." I stared at him from my C++ coding haze. He handed me a CD-ROM. "Layer setups, and this is just a smattering-they're everywhere! Funny thing, though, a couple of nice expert applications passed by my nose, and you know what they were missing? Layer setups!"
Tip #1954 (Make Layer Current) from David Trembley is a dialog box utility that lets you select a layer to make it current. If the layer doesn't exist, it's created based on the internal standards of the routine. The AutoLISP code handles the layer colors and linetypes so you don't have to wade through AutoCAD's Layer dialog box. The DCL file must be in a folder that AutoCAD searches for the function to operate correctly. Load the code and type Mlayline to activate the command. This is a great utility for setting up a single layer and then using it immediately. It's useful even if you need to adapt it to match your own internal standards.
If you want to prepare a suite of drawings or work with more than one drawing at a time, VBA is the tool to use. Tip #1955 (Manipulate Layers in a Drawing Group) is a VBA macro that lets you manipulate the layers in a group of drawings. In this case, Benoit Lefebvre wanted to go through the drawings and modify the layer names of objects generated as a result of the solids manipulation commands Solview and Soldraw. This routine is a wonderful example of how you can use VBA to quickly change multiple drawings.
If you want to do something similar inside Visual LISP, Jeff Sanders' Tip #1956 (Batch LISP) builds a script file that loads and runs a Visual LISP module of your choice in a selected set of drawings. Because Visual LISP maintains a memory map for each open drawing in MDI (multiple document interface) mode, you can't have a Visual LISP function run against multiple drawings. Each time a drawing becomes the active document, the memory map sets for just that drawing. One way around this is to use the object references in Visual LISP to prevent the other document from becoming the active one. This isn't easy, but as Jeff shows us, where there's a will there's a way. He began by using a script file created and started with Visual LISP. Scripts can load a series of drawings and evaluate (load) AutoLISP program files. Jeff's example lists the layer names in a series of selected drawings. Included in this tip is another utility that I broke out and presented as Tip #1957.
Tip #1957 (Select Multiple Files) presents a dialog box for filename input. This dialog box is different from what the native Getfiled dialog box produces inside Visual LISP in that you can select multiple files. The Selectfiles function requires a dialog box defined in selectfiles.dcl, located in the AutoCAD search path. Use this great utility to select multiple files through a dialog box.
Sometimes you get drawings with colors that just don't fit your standards or styles. Clay Riggs must have had that problem more than once because Tip #1958 (Change Colors) makes it easy to do this type of edit. The command Chlc lets you select an entity representative of the layer to change and then pick a color code from the standard AutoCAD Color dialog box. This is a nice utility that demonstrates the productivity-enhancing powers of Visual LISP for streamlining operations.
Tip #1959 (Blank Out Text in Attributes), supplied by Will DeLoach, a master of Visual LISP programming, lets you blank out text values inside attributes. I can see using this in conjunction with a massive block library where each block carries extra text attributes that I may or may not wish to display in the drawing. Not only is this a great program, but also an example of programming we should all work toward.
Speaking of the masters, Harry once again gives a nod to Watson Kilbourne, who supplies some of the best hatch patterns. You can use his latest, c-stone.pat (Tip #1960, Course Bricks and Stone Hatch), to draw coursed bricks or stone patterns.
Keep in mind that if you submit applications that create drawings, I test them using AutoCAD 2005 in a blank drawing. Your application should include everything needed to set up layers, line styles, and any other drawing specifics. When others download your code, it will run in foreign environments and your application should assume nothing is right.
Bill Kramer, president of AUTO-CODE MECHANICAL, contributing editor for Cadalyst, former headmaster of the Wizard's Lab at PointA, and refugee scribe from Cadence, is a programmer and writer with more than 20 years of experience in the field of CAD/CAM/CAE.
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!