cadalyst
Manufacturing

Top Tip for October 2004

14 Oct, 2004 By: Bill Kramer Cadalyst

Visual LISP with a dash of VBA.


GET THE CODE
Download free code for this and all articles. Look for OCT04.exe in Get the Code.

Tips are tested with AutoCAD 2005, 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. All published tips are entered into the annual Hot Tip Harry Contest. E-mail your tips and tricks to harry@cadalyst.com.

"You been holding these back?" I muttered under my breath as I looked through the CD. Harry chuckled. "I knew you'd like 'em," he growled. This month we've got Visual LISP code to share along with VBA code that uses reactors to make AutoCAD do wonderful tricks. I guess you could say this is Harry's form of "Trick or Treat."

Manipulate Data
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.

Code Notes
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.


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!