Hot Tip Harry: Tips from Our Readers -- December 2006

7 Dec, 2006 By: Bill Kramer

Harry offers up a few of his own tricks.

Download code for this and all articles. Look for DEC06.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.

All published tips earn the author a Cadalyst
t-shirt, and the tip judged best each month earns the author $100. Click here for details about the Hot Tip Harry Challenge 2006.

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!

This month Harry takes a vacation from reviewing tips submitted by readers and presents a few of his own tricks and tips. These tips are based on discussions at Hot Tip Harry's Help forum, with an eye toward providing examples that are useful (at least to some) and that teach an AutoCAD programming concept. Hope you enjoy your holiday-season treats!

Note: This month's tips are not numbered according to Harry's usual method, but can be found in the Get the Code section with this month's code.

Harry's Holiday Tip #1
Solid Arrowhead to Polyline Outline is a special example using LISP to change data coming in from another source. In this case, the drawings that are manipulated came into AutoCAD with arrowheads represented as solid objects, and the user wanted to change them into something else. Originally, the request was for an outline of the solid object -- that's where Harry picked up and went off on his own. Tip #1 is composed of the LISP function SOL2PL found in the source code file for this month's Get the Code. Load the LISP and type SOL2PL at the Command line to run. It's automatic from that point forward as it attempts to locate solid objects and convert them to polyline outlines.

Functionally, the programming steps are simple. It finds all the solids to be converted, grabs the points and draws the outline. The coding is a bit more complex, but not by much. You can study the source code. Functions like this are typically run once for each drawing that is imported into AutoCAD so that oddities are cleaned up. You can expand this example in many directions to suit your own purposes.

Harry's Holiday Tip #2
Pretty Print a List is a utility that has been around for ages in the LISP world and here it is again in a recursive style. (DISP-LIST) is a function that accepts a list as an argument and displays the list in the AutoCAD text window. Instead of just dumping the list to the screen, (DISP-LIST) displays each new open parentheses grouping spaced over by the nesting level so you can visually read through a complex list structure without straining your eyes.

This function set consists of two functions. (DISP-LIST) is one line that calls up the (R-DISP-LIST) function, a recursive routine that displays the list contents. (R-DISP-LIST) has two parameters: the list to display and an integer representing the current tab-over amount. Initially, the value is supplied as negative, which indicates the start of a new list.

Recursive functions are functions that call themselves inside the function after reducing the data in some way. Recursion works very well for list handling, because any structure of list can be manipulated as demonstrated in this simple example. This example has been used in classes and other places, but has never appeared in Hot Tip Harry before. Plus, someone on the forums was wondering about a quick tool to display lists in a readable format a while back.

Harry's Holiday Tip #3
Block Usage Report displays a summary of how blocks are used in a drawing. Some time ago, a forum reader asked if anyone knew of a way to check how a block was used in a drawing. Was it inserted anywhere? Was it part of another block? How many times was it used? These questions and others can be answered by investigating the blocks table in AutoCAD. When loaded and run, BlockGem displays the block data in a variety of ways on the AutoCAD text screen.

This tip is composed of a command function (C:BLOCKGEM) with a small suite of utility functions. Programmers wanting an example of list manipulation will find this one particularly interesting because the entire function suite is based on the construction of a nested data list from information in the block table. There are plenty of MAPCAR, LAMBDA and a few APPLY functions that make up the meat and potatoes of the report output.

Harry's Holiday Tip #4
Sum the Area lets you select objects and learn the total area. After loading the LISP code, type Areasum at the Command prompt. Areasum asks you to select objects, one at a time, displaying the cumulative area with each selection. When no more objects are selected, the total area is shown using an AutoCAD alert dialog box. Programmers who investigate the source code will also find a version of the area sum as a utility that adds up the total area of a selection set.

Harry's Holiday Tip #5
Utility to Parse Comma Delimited Input is very useful for programming applications that read data from files or other devices. The most common form of record data sharing between programs is to use text strings with commas (or some other delimiter)between each of the values. This utility is for programmers only and is not a command function. To use in your programs, supply a text string that is comma delimited. The result is a list with each member being a string. Note that the program solves the delimiter problem using recursion, and is a great example for teaching that concept.

Harry's Holiday Tip #6
Linking Excel and AutoCAD via Visual LISP can be used by a lot of applications developers. There are numerous examples on the Web, but most are not provided in a programmer utility format, so Harry decided to put these out there again. These simple utilities solve the basic interface problem for Visual LISP programmers. The first is SETUPXL which accepts a filename of an existing spreadsheet along with a sheetname. It establishes a set of global symbols that are used in the other functions to read and write data. The two interface functions are PUT_CELL and GET_CELL. These functions write and read string data from the open Excel spreadsheet given the row and column number. Because LISP programmers normally find it easier to work with numeric values for rows and columns (who doesn't?), this function suite also includes a function for converting integer column numbers into the string representation found in Excel. Hope you can use these! Note that you must change the reference to the "tlb-filename" in the SETUPXL function to match your system. This is the location of the Excel object library.

Function Junction
All of these function examples are partial answers to questions posed at the Hot Tip Harry forums, and I look forward to hearing from everyone on how to improve or adapt them to other needs. They have been tested, but not all circumstances have been completely considered. If you run into a problem, report it to the forum and let's work together to make them better.

Announcing: Hot Tip Harry Challenge 2007
Cadalyst announces the extension of the Hot Tip Harry Challenge for 2007. Next year we'll give away a t-shirt for every tip published, plus a $100 prize to one lucky tip author each month. In the fall, we'll draw a name from all published tip authors and send one lucky reader to Autodesk University 2007 in Las Vegas, Nevada. Harry will return to his usual line-up of user-submitted tips next month, so get your LISP and VBA routines in now for your chance to win.

Happy Holidays to everyone! Keep on programming!

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!