Hot Tip Harry15 Oct, 2004 By: Bill Kramer Cadalyst
Visual LISP with a dash of VBA.
Start easy and get the job done is the motto for a utility from Matt Stormont, Offset and Layer (Tip #1981). This command function combines the Offset command with the Layer command to move the offset object to the current layer. Load the LSP file and type OffsetToLayer at the command line to activate. The normal Offset command sequence starts, but the resulting offset is placed on the current layer instead of the same layer as the original object. This is a cool example of how easy it is to automate AutoCAD commands inside Visual LISP.
Multiplication Total (Tip #1982) from Tom Johnson lets you apply a multiplication factor to text objects that contain only numeric values. Type Total at the command line after you load the LSP file and then supply a multiplication factor. Pick two points to describe a window around your text, and the function takes it from there. Careful! There's little to no error checking in this function, and the results are truncated if you use decimals.
Isometric Cursor Settings (Tip #1983) from Shannon Richardson has three files. Place them in a folder normally searched by AutoCAD and load the is.lsp file. Type Is at the command line to quickly shift cursors for isometric drawing views. This utility is very handy and a well-written example for anyone seeking nicely documented and presented code samples.
Up the Ante
Our next submission is a wonderful demonstration of VBA power. Add Calligraphy to RevCloud (Tip #1984) from Martin Fryer gives us a DVB routine that latches onto the command event in AutoCAD and adds a new feature to the RevCloud command. This example is a powerful demonstration of some of things you can do with just a few lines of code inside VBA. Use VBALOAD to load the DVB file. If that doesn't work, try importing the text provided in the downloaded ZIP file into the VBA IDE. Once the program loads, it's running and waiting for you to use the RevCloud command.
Another very nice routine that demonstrates reactors comes from Leonid Nemirovsky. Link Area Text to Boundary (Tip #1985) lets you define a polyline and then select it as an area region. The area value displays as text at the location of your choosing, then the magic begins. As you change the endpoints of the polyline that defines the area boundary, the text for the area regenerates. This is a classic example of how one entity can cause another entity to change under program control. This tip runs only inside AutoCAD 2005 or higher because of Leonid's coding with the Field elements. Look at this code to learn how you can link objects together using Visual LISP reactors.
Simple and Useful
Back to some simpler coding, but useful in the tool library. Set Limits Outside Extents (Tip #1986) from Walt Bedinger zooms the drawing out to a view 105% greater than the actual drawing extents. Load the LSP module and type Setlim to run. After zooming out, the routine sets the drawing limits to the current screen view. There's nothing tricky to the coding?it just zooms to the extents, then zooms again by a scale factor. The limits are established by changing the values in the system variables.
Watson Kilbourne offers up a pair of patterns that you must add to your library. ArcPaver (Tip #1987) is a paving pattern. RiverRock (Tip #1988) adds a nice river rock pattern to an area. Use the Bhatch command and select the PAT files from the custom list after placing them in the standard pattern search folder. These take a lot of time to create, and Harry tips the hat once again to Watson for his outstanding work.
Hey, folks, don't send code protected by a password or compiled. Unless we can review the source code, we can't share it with other Hot Tip Harry readers and make it eligible for the prize money. Keep those tips coming in, and vote for your favorite tip.
In her easy-to-follow, friendly style, long-time Cadalyst contributing editor and Autodesk Technical Evangelist Lynn Allen guides you through a new feature or time-saving trick in every episode of her popular AutoCAD video tips. Subscribe to the free Cadalyst Video Picks newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!