AEC

Top Tip for October 2004

15 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


AutoCAD Tips!

Lynn Allen

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 Tips & Tricks Tuesdays free e-newsletter and we'll notify you every time a new video tip is available. All exclusively from Cadalyst!
Follow Lynn on Twitter Follow Lynn on Twitter


Latest News from Cadalyst Partners
Feed
The Infinite Resource: the case for GMO instead of organic farming   22 May, 2013

I have no desire to eat pesticides. I really don't. Actually when I was a child growing up in New Orleans, a "fog truck" used to come down our...More>>Read more It's Alive in the Lab blog posts>>

Feed
TERA Semicon Drives Its Own Destiny with CAD and PDM   22 May, 2013

When you read the history of TERA Semicon, you can see right away that the company has had a strong vision and direction from Day 1. The South Korean...More>>Read more PTC Creo blog posts>>

Feed
Excel Hyperlinks & Document Management Tricks   22 May, 2013

Do you have to keep track of a lot of different folders and files? Do you wish you peers could open the correct Revit file? Are you tired of having...More>>Read more BIMbuilder blog posts>>

Feed
SolidWorks Simulation Tips: Parameters and Design Studies   22 May, 2013

In my opinion, one of the most underutilized tools in SolidWorks Simulation is the Design Study.  Design studies allow you to easily set up a...More>>Read more SolidWorks Blog posts>>

Feed
Is This the All-in-One Bike Helmet of the Future?   22 May, 2013

For those used to cycling on busy city streets (NYC comes to mind), the need for swift reaction times could be compared to that of catching a fly...More>>Read more SolidSmack blog posts>>

Poll
What type of input device (besides the keyboard) do you use at your primary CAD workstation?
Standard mouse
Trackball mouse
Programmable mouse
3D navigation device
Pen/tablet
Multiple devices
Submit Vote




Considering Wide Format Printing Solutions?
Four FREE White Papers Available:






Subscribe Cadalyst Newsletters