cadalyst
General Software

AutoLISP Solutions: Automated drawing coversheet

31 Mar, 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)
(load "coversheet")
)
(coversheet)
(princ)
Figure 1. Dialog box for Coversheet command.

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.

Figure 2. Coversheet inserts the sheet selected in the dialog box.

Programming notes
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)
(setq csheet
(cond
((= 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.


About the Author: Tony Hotchkiss


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!