AutoLISP Solutions: Automated drawing coversheet1 Apr, 2002 By: Tony Hotchkiss
Add custom toolbars to your AutoLISP program interfaces.
Julie Conley requested a routine to insert any one of four template coversheets into new and existing drawings. If an existing drawing has a coversheet, the routine provides an option not to insert one. AutoCAD uses templates for new drawings, but they are cumbersome to add to existing drawings. The coversheets that Ms. Conley uses are for architectural drawings, but you can modify the solution for wider applicability.
This AutoLISP solution comprises COVERSHEET.LSP, COVERSHEET. DCL, and ACADDOC.LSP. To load any number of AutoLISP programs, simply add the (load) function to your ACAD.LSP file, if it exists. Later versions of AutoCAD, such as AutoCAD 2000 and 2002, can open many files simultaneously. In these cases, the ACAD.LSP file has a counterpart, called ACADDOC.LSP, for multiple documents.
How to use COVERSHEET.LSP
Download the required files from Cadalyst's CAD Tips site and save them in AutoCAD's Support directory. If you already have a file named ACADDOC.LSP in your Support directory, append the contents of the downloaded ACADDOC. LSP file to the end of the existing file:
|(if (not coversheet)|
Adding these lines automatically loads the Coversheet program and executes it. In a multiple-drawing environment, the ACAD.LSP file executes only once, at the beginning of the session, whereas the ACADDOC.LSP file executes every time you open a drawing. You can force the ACAD.LSP file to execute with every drawing by setting a system variable or the user options, but that is more complicated than using ACADDOC.LSP.
The Coversheet program inserts one of the four drawings, named NH24X36.DWG, NH30X42.DWG, R24X36.DWG, and R30X42.DWG, that Ms. Conley requested. These drawings should also exist in the AutoCAD Support folder.
When you start a new drawing or open an existing drawing, you see the dialog box shown in figure 1. There you choose to insert any one of the four coversheet files indicated, or none. Figure 2 shows the "New home E-size" coversheet selected in the dialog box.
I used the AutoCAD 2000 Visual LISP editor to write the program, but it should also work in AutoCAD 2002. If you use earlier versions of AutoCAD, you may be able to substitute the ACAD.LSP file for the ACADDOC.LSP file. The Coversheet program works in either a single- or multiple-document environment (controlled by system variable SDI).
The program starts with a modified version of my usual system variable management functions, followed by the dialog box driver function (coversheet). This function gets the value of the radio button and calls the function (set-cs). (set-cs) assigns the value of the global variable CSHEET:
|(defun set-cs (val)|
|((= val "NHD") "NH24X36")|
|((= val "NHE") "NH30X42")|
|((= val "RD") "R24X36")|
|((= val "RE") "R30X42")|
|((= val "none") "none")|
|) ;_ cond|
|) ;_ setq|
|) ;_ defun|
After the routine closes and unloads the dialog box, it uses the CSHEET variable to insert the drawing that the variable represents. The drawing is zoomed to its extents (figure 2). As always, contact me with comments or requests.
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!
Autodesk Gallery Powers of Design Exhibit: 10**15 Cat's Eye Nebula 23 May, 2013
Load ‘Em Up! Stackers, Conveyors, and Advanced Assembly 23 May, 2013
Excel Hyperlinks & Document Management Tricks 22 May, 2013
New Certification Logos And Certificate Designs Available 23 May, 2013
Cool Tools of Doom n’ Stuff: Episode 22 23 May, 2013