Hot Tip Harry: Tips from Our Readers -- December 20068 Dec, 2006 By: Bill Kramer
Harry offers up a few of his own tricks.
Note: The tips are not numbered with Harry's normal tips, 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.
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.
Happy Holidays to everyone! We will continue to publish user-submitted tips next month, so get yours in now for your chance to win a prestigious Hot Tip Harry T-shirt and our super-secret 2007 promotion.
Keep on programming!
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!
My ConnectMyDNA Results 21 May, 2013
TERA Semicon Drives Its Own Destiny with CAD and PDM 22 May, 2013
SolidWorks Simulation Tips: Parameters and Design Studies 22 May, 2013