Happy Holidays and Happy Programming (Hot Tip Harry AutoCAD Tutorial)1 Dec, 2008 By: Bill Kramer
2008 goes out with a bang-up batch of 23 tips from Harry, including a Top Tip to cross-reference symbols and functions in your LISP code.
Going forward, Harry will make frequent updates to the CAD Tips site, so check back often for the latest new code, always listed under Recently Posted CAD Tips. Bimonthly editions ofCadalyst magazine also will include updates about the latest tips. Questions? E-mail the editors.
Harry's going online this month with a big set of holiday tips to keep you busy during those long winter nights. He's bursting at the seams with a batch of 23 new tips. So buckle up, there's a lot to cover in this sleigh ride.
Flat Pattern Generator for Sheet-Metal Transition Cones
Steve Pettey submitted Flat Pattern Generator for Sheet-Metal Transition Cones, which is a cool LISP command named C:Cone-FP and includes a LSP and a PDF document. This command is a flat pattern generator for sheet-metal transition cones. Draw the cone in 3D as a solid, then draw the cuts (penetrations) on the model. Isolate the cone and explode all the surfaces and bodies. Next load the LISP code and run the Cone-FP Command line function. The routine will ask you to select the apex of the cone and all the cutouts. The final result is the flat pattern with cutouts as polylines -- all set for the CNC process. This serious power tool gets designs to the shop floor for fabrication. Very nice. The included PDF document helps explain the process in detail.
Automatically Annotate Coordinates for Block Inserts and Point Objects
Ronald Maneja, a frequent tipster, sent two tips this month. The first, Automatically Annotate Coordinates for Block Inserts and Point Objects, is another gem from his collection named WPOB. This LISP command function automatically annotates coordinates for block inserts and point objects with an Easting and a Northing value. Load the LSP file, then type WPOB to run. You will be prompted to apply a scale factor to the text height of 2.5 (millimeters). Next, the routine will ask you to locate the block inserts and point objects. When you have located the objects you want to label, the routine will then automatically apply two text labels at each point. The text labels are the Easting (X ordinate) and Northing (Y ordinate). Automatic drafting like this utility is the greatest. A tip of the hat from Harry!
Numeric Manipulation of Text Values in a Drawing
Maneja's second tip provides a text object calculator that is used for performing basic numeric manipulation of text (and Mtext) values in a drawing. To use Numeric Manipulation of Text Values in a Drawing, load the LSP file and then run the Mmath command function. You will be asked to locate three sets of text/Mtext objects in the drawing. The first and second sets will be used to replace the values in the third set by going through each member in the first and second set, applying the desired math operative, and then placing the result in the associated text object from the third set. You must select the same number of text/Mtext objects for all three sets. This calculator is very handy when updating a table of numbers. Operations available include the basics: addition, subtraction, multiplication, and division.
Export Text from a Drawing to an Excel Spreadsheet
Pedro Ferreira, another of Harry's favorite tipsters, submitted a LISP command -- Export Text from a Drawing to an Excel Spreadsheet C:Txt2Xls -- for exporting text from a drawing to an Excel spreadsheet. This command will attempt to locate text in columns based on your selection criteria. Start by loading the LISP code and typing Txt2Xls at the Command line. The program first will attempt to link with the Excel application, which must exist on your computer. Next, the program will ask you to select text using two points to define a rectangular window. Only text objects will be selected inside this window. In the next step, the program asks you to select to sample text objects from the same column. These text objects will be used to determine a deviation factor for locating columns of text (that way your text does not have to be exactly lined up, just close). The rest is automatic as the text objects are extracted and written to a new workbook inside Excel. This program is very cool when it works, but make sure you have Excel installed. You might need to edit the code yourself for specific versions of Excel -- for help, visit Cadalyst's Hot Tip Harry-Help Discussion Forum.
Save Drawings with Updated Revision Numbers
In a second tip, Save Drawings with Updated Revision Numbers, Ferreira shows us a utility for saving drawings with updated revision numbers. This CAD management tool lets you name your drawings with sequential numbers. Start with a base drawing. When you are ready to save a version of the drawing, load the LISP code and type RN. The current revision number, number of versions on disk, and other details will be displayed in an alert box. You can then select whether to save the drawing using the next version number. Drawing version numbers are appended to the end of the drawing name using a hyphen followed by the number value as in "Drawing-1" for the first version saved of a drawing named simply "Drawing." Very cool, Pedro.
Find and Change Objects by Color Setting
Ed Jobe sent in an excellent little VBA macro named ColorToByLayer that reads through the current drawing layouts and changes any entity objects that have a color setting that is not "by layer." Changed entities are moved to a new layer named "CBL_" plus the color number. The entity color code is then reset to be "by layer." To use Find and Change Objects by Color Setting, you need to launch AutoCAD's VBAide, then select the File and Import File . . . and navigate to where the BAS file is located. The BAS file will load into a module. Select the module in the project window pane and then click the run button (F5 key). The macro ColorToByLayer should be available to run, so click it, and the rest is automatic. This utility is a great VBA example for those looking to learn how to use this marvelous customization tool.
Detach External Drawing References not on Locked Layers
Another regular tipster, Ron Perez, sent in two tips this month. The first, Detach External Drawing References not on Locked Layers, is a neat example of object manipulations using Visual LISP. The command function Dax included in this tip detaches all external references in a drawing that are not on locked layers. This tip is an excellent demonstration of how to loop through a block table using object references in Visual LISP. Each object in the block table is first checked to see if it is an external reference. When an external reference block is found, all instances of the block in the drawing are collected into a selection set. That selection set then is processed in a loop in which items on unlocked layers are detached (resulting in a normal internal block reference). This example is wonderful for advanced programmers who are looking to see how selection sets, lists, and Visual LISP object references can work together elegantly.
Adjust Leader Dimensions Landing Positions
In his second tip, Perez submitted an edit utility that adjusts the positions of leader dimensions landings. An associated GIF file included with Adjust Leader Dimensions Landing Positions demonstrates the operation of the edit utility. Draw the leader dimensions first, then load the LISP code. Type AlignLandings at the AutoCAD Command line, then locate the dimension objects using a window. Next, select the one leader landing that will serve as a location template for the others. The other leaders are automatically adjusted as needed. This cool utility program demonstrates how Visual LISP object manipulations can make a seemingly complicated task easy.
Label Spot Elevations on Grading Plans
Mike Roberts submitted a LISP command called ZCR, which is an annotation tool for labeling spot elevations on grading plans. Load the LISP code, then type ZCR to start it. The Label Spot Elevations on Grading Plans function will ask for two points. The first should have a z-value or elevation associated with it. The second point is used to determine the direction of the annotation from the first point. The label consists of the elevation as determined from the first-point selection on top with a user-input label underneath. A line is drawn between the two text objects to complete the annotation.
Locate and Open Drawings by Name
Kevin Loth's LISP command LOpen will attempt to locate and open a drawing (or image), given a name. Kevin's variation of the universal open looks for revised names (based on the standards Kevin uses) including a "D" prefix or a "-1" suffix in the name. If no DWG type is found the program, it then proceeds to look for a TIFF, BMP, or a JPEG file, starting the Explorer application in Windows to view it when found. Locate and Open Drawings by Name is very useful when you are looking for a graphic image or drawing and know the name, but you're not sure where you saw it.
Display Upper ASCII Characters in a Drawing
Display Upper ASCII Characters in a Drawing from Joseph Floss is a simple LISP command named Symb1 that displays all the upper ASCII characters in a drawing for your reference. You can then use "%%" with the ASCII code number inside text to access the upper ASCII character set. The upper ASCII set contains a variety of symbols that could be useful in your annotations. This function displays the reference values. The integer code number shows along with the symbol. When you type text into the AutoCAD Text Command, you can use the number value preceded by the double percentage signs. Harry says he can never remember those character values, either! Thanks, Joseph.
LISP Customization Commands
In the first of two tips, Roy Knapp submitted a group of LISP commands, including LD, Freeze_Date, and MXPG suite. These command functions demonstrate how to make AutoCAD your own. LD is a leader command that uses Mtext (written some time ago but still useful) and lightweight polylines. Freeze_Date and MXPG are two title-block manipulation examples for placing the current date and setting the page count based on the number of tabs. These cool little tricks from Roy's library get a nod and a wink from Harry.
Render Bricks above an Archway
Knapp's second tip, Render Bricks above an Archway, is an architectural tool for rendering bricks above an archway. With the LISP command Brick_Arch, user input includes an arc entity selection along with the brick-and-mortar sizes. From then on, the rest is automatic. Bricks are drawn as closed lightweight polylines and spaced based on the mortar spacing distance input. This clever and useful routine is another utility from Roy's chest of power tools.
Nonskid Flooring Hatch Pattern
With his tip Nonskid Flooring Hatch Pattern, Joel Sanders shares his Tread pattern for nonskid flooring. To use the pattern, copy the PAT file into a folder that is searchable by AutoCAD. Then use the custom pattern button to locate the Tread pattern. The program creates a nonskid (raised areas) flooring pattern. Nicely done.
Reading and Writing Data with Excel
Reading and Writing Data with Excel Files was sent in by Perry Mason. The LISP commands -- AttRead and AttWrite -- are attribute import and export utilities. AttWrite will create a comma-delimited file (CSV) that can be read and processed by Excel. The data extracted is for a single block instance. When it runs, you will be asked to pick the border or block for the extract. A CSV file is created that contains each attribute tag and value in a line. AttRead is the opposite. Select the block, and the tag/value file is read and the attribute values are changed based on the tag names. This simple routine is a great example of how you can pass data from drawings to other applications and get back other data. Nice job, Perry!
Draw Cabinet Elevations
Jay Thomas submitted a cool tool for drawing cabinet elevations based on your input. Draw Cabinet Elevations uses the LISP command Cab_Elev2 or CE2 to provide an expert drawing system just for cabinet elevations. This tip has multiple files and includes a library of blocks that must be located in a folder named Cabinet2 under the LSP file folder. A text file explains the contents of the various files included. To use this power drawing tool, start with two horizontal lines approximately 84" apart. Place the cabinet components working from the left. A lot of other goodies for cabinet designers are available in this tip, and an editable data file lets you add your own components. Draw Cabinet Elevations is a very cool expert system that will save a lot of time when you are laying out cabinets in AutoCAD.
Restrict Stretch Operations
Park Suyeong offered the EStretch LISP command, which is an easy-to-use dialog box for the Stretch command that restricts the stretch operations to the quadrant endpoints. Load the LSP code and type EStretch to start Restrict Stretch Operations. Pick two points windowing the entities that are to be stretched. A dialog box will appear with four direction boxes. Fill in the values to stretch and pick one of the buttons to make it happen. The dialog box buttons are a bit odd in appearance because Park used the Korean version of AutoCAD -- you can change the contents by adjusting the LSP file as desired; however, it's pretty easy to run this tool as is. It just goes to show that LISP is a common language for everyone!
Looking for a set of process and instrumentation diagram (P&ID) linetypes? Look no further. Stephen Bindon's tip contains a PDF document of the linetypes, including LIN, SHP, and compiled SHX files. The LIN and SHX files must be in a folder that is searchable by AutoCAD. To use these linetypes, define a new text style named LType. Next use the Linetype Command to load the PID.LIN contents and select the linetype you want to use. Note that without the LType text style some of the linetypes cannot be loaded. As an alternative, you can rename the LType entries in the LIN file to Standard. Linetype Library makes a nice addition to your library.
Draw Tube Section Breaks
Laurie McGaw got tired of drawing tube section breaks and wrote a set of LISP macros to do it fast. And then she shared them with Harry, so you won't have to draw those break details either. Draw Tube Section Breaks comprises two LISP modules -- S-Breaks.LSP and S-TBreaks.LSP -- that create the standard "S" break symbols for depicting long sections of tubes on a sheet. Two versions are supplied. S-Breaks.LSP contains the command function SBRK for solid bar tubes. S-TBreaks.LSP contains the command function STBRK for drawing hollow tubes with a known sidewall thickness. This utility is a very useful and easy-to-run function that makes drawing these details fun again.
Purge, Audit, and Save Tool
The Purge, Audit, and Save Tool from Michael Kolomiyets is an advanced purge-audit-save utility for cleaning up drawings before saving. To use, load the PAS.LSP file, then type PAS. The rest is automatic. First, the Purge command cleans up unreferenced objects. Next, it checks the tables to make sure no errors or bad links remain. Last, the drawing is saved using the current name. In some cases, this utility can reduce the size of an active drawing considerably. The reduction depends on the amount of extraneous stuff your drawing is carrying. Nicely programmed using Visual LISP, and excellent error trapping!
Turn Text Object Background Masks On and Off
Andrew Maser submitted a background mask on/off utility written in VBA. AdmBbMask is a macro for switching the background mask of text objects on and off. The DVB file included in Turn Text Object Background Masks On and Off contains the module for the macro. Load the DVB into AutoCAD, then select the macro AdmBgMask to run it. You will be prompted to select text objects. Selected text objects will have their background mask flag inverted. Not only is this macro useful, it also serves as a great example of how to manipulate objects in AutoCAD using VBA.
Label Square Acreage
Label Square Acreage from Howard Pennington makes it quick and easy to label the square acreage of areas. Draw perimeters as polylines, then load the LISP code. Type SQA to activate the tool inside AutoCAD. The first request is to enter the text size for the labels. Next, select to either add a single label or multiple labels. Multiple labels are used for multiple areas. You then can select a polyline depicting an enclosed area. The AutoCAD Area Command is used to accept one entity. The next input request is for the location of the area label. You can repeat the process to label all the areas. When you select to stop the utility, you will be asked to locate a point where the table of areas is to be created. This productivity tool is very nice for annotating areas in a plot layout quickly and accurately.
Cross-Reference Mapping of Symbols and Functions
For those who are seeking a way to control their use of symbols in LISP programming, Peter Wolf offers the VBA project called Lisp2Ref. The macro in this utility creates a cross-reference mapping of the symbols and your functions. This tool is of great value for programmers who want to document the use of symbols in their LISP code. To use, open the program using the VBAMan Command inside AutoCAD, then load it. Enable the macros and run the macro named "Start here." Select an input and output file, along with the options to be cross-referenced, and then select either the Document button (writes to file) or the View output with Notepad button. This tip includes example information and more explicit documentation with the download. If you are like most of us and have an extensive library of LISP code, this tool will help you keep it well documented. A tip of the hat from Harry for this extensive tip with loads of great examples that demonstrate how to do cool stuff inside VBA.
That's it from Harry for the Year 2008. I do hope you found something useful in this pile of tips -- a lot more than we normally share each month. But that's because we're going online now! Stay tuned, Harry's still got your tips.
Keep on programmin'.
Join the Hot Tip Harry Challenge
Harry needs your tips! Do you have an original routine written in VBA, Visual LISP, or even ObjectARX for AutoCAD customization? Send it in, with all the source code, to firstname.lastname@example.org. Your tip may be needed by others now, so don't delay!
Subscribe to Harry's Code Class
Cadalyst's Hot Tip Harry helps programmers and programmer wannabes learn the ins and outs of AutoCAD customization in his monthly e-newsletter, Harry's Code Class. Subscribe to Harry's Code Class today and start building your programming expertise.
Hot Tip Harry Discussion Forums
Harry is standing by online to aid AutoCAD users and programmers. Cadalyst's Hot Tip Harry -- Help! Discussion Forum offers assistance with AutoCAD programming and customization problems. Hot Tip Harry -- Requests Discussion Forum can help you locate a specific LISP or VBA routine for AutoCAD. Participation in Cadalyst Discussion Forums requires registration, but it's free.
Get Your Weekly Fix of AutoCAD Tips
Cadalyst's Tips & Tools Weekly e-newsletter mails each Monday, delivering AutoCAD tips by readers for readers -- all reviewed by Cadalyst's volunteer Tip Patrol. Plus, you'll receive a rundown of new online CAD resources, deals and freebies, new CAD-related hardware and software products, and more. View the Cadalyst Tips & Tools Weekly archives and subscribe today!
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!
AutoCAD 2013 Service Packs 17 May, 2013
Teaching Old Designs New Tricks 17 May, 2013
Ideate - Ideate BIMLink for Revit 2014 now available 17 May, 2013
5 SolidWorks Tips You May Have Never Seen Before 16 May, 2013
EngineerVsDesigner: E69 – Steven Heller 17 May, 2013