Full-Fillet Three Lines (AutoLISP Solutions Tutorial)1 Nov, 2008 By: Tony Hotchkiss
This bit of code lets you automatically fillet three lines by simply selecting them in clockwise or counterclockwise order.
Bill Baker asked for a new way to fillet three lines in AutoCAD by picking them in clockwise or counterclockwise order. The result would be a full fillet in the sense that an arc would be constructed tangential to all three lines with a full trim.
Bill sent me a LISP routine that worked on old drawings but does not work in later versions of AutoCAD. The program was so old that it used no ActiveX Visual LISP methods, so I decided to ignore it and write a new program from scratch. It is usually easier to write new programs than to figure out how to fix old ones because programming techniques change quite often.
The AutoLISP Solution is FILLET-3-LINES.LSP, which allows the user to enter F3L on the Command line, then select each of the three lines in either clockwise or counterclockwise direction. The lines are then filleted automatically, and the fillets are placed on the same layer as the first selected line.
Get the Code!
Download the FILLET-3-LINES.LSP file from Cadalyst's CAD Tips site. Save the file in AutoCAD's Support directory. Use the Appload facility by selecting Tools / Load Application, then use the browser to select the FILLET-3-LINES.LSP file.
How to Use the FILLET-3-LINES.LSP Code
To start the program, enter F3L and you will be prompted to select the first line, then the middle line, and finally, the last line. Figure 1 shows sets of lines to be filleted, and Figure 2 shows the result of the fillets.
Figure 1. Sets of three lines before filleting.
Figure 2. Results of filleting.
After three lines have been selected, they are automatically filleted. The program can be restarted by simply hitting Enter, as is normal for repeating any AutoCAD command. If no lines are selected, an error message to that effect displays on the Command line.
The program starts with my usual error handler and system variable manager. These functions are followed by FILLET-MAIN, which starts by defining the global variables *thisdrawing*, *modelspace*, and *utility*. The Visual LISP utility VLA-GETENTITY is used three times to create each of three line objects selected by the user. FILLET-MAIN proceeds to calculate the locations of the endpoints of two new lines, and the start, end, and an intermediate point of an arc. The new lines are created by successive calls to MAKE-NEW-LINE, and the arc is created by using the VL-CMDF command "ARC". My SETV and RSETV functions are used to place the new objects on the layer of the first line selected by the user. This code fragment is shown here:
(setv "CLAYER" lyr)
(make-new-line L1a P1 A1 1)
(make-new-line L3a P3 A3 2)
(vl-cmdf "ARC" P1 P2 P3)
Note that the calls to MAKE-NEW-LINE have four arguments, the last of which is either 1 or 2. Those numbers are used to control the order of the start and endpoints of the lines using the logical IF function as follows:
(if (= num 1)
(setq start startpt)
(setq end endpt)
) ;_ end of progn
(setq start endpt)
(setq end startpt)
) ;_ end of progn
) ;_ end of if
MAKE-NEW-LINE uses the VLA-ADDLINE method to create new lines in model space.
As I was writing this column, I received an e-mail from a reader who wanted to use an earlier AutoLISP routine in which I had also created objects in model space. The reader wanted to modify that routine to create the objects in paper space instead of model space. In a future column I will add some code that gives a choice of model or paper space so the code can be inserted into any of my routines to make them more flexible.
In the meantime, I look forward to receiving your comments and requests for AutoLISP Solutions. Please contact me using the links below.
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 free Tips & Tools Weekly e-newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!