[CAD LISP] Extend Lines on Both Sides Instantly (EXD.lsp)
When creating structural grid lines, extending centerlines beyond wall perimeters, or adjusting clearance boundaries in AutoCAD, you frequently need to lengthen lines equally on both sides. Doing this manually with native commands usually means running LENGTHEN with the Delta option twice per line—or clicking grips and typing extension values at both endpoints individually.
The EXD.lsp (Extend Both Ends) routine automates dual-direction extensions into a single selection step. It calculates both start and end points of open lines or polylines, applies your specified extension distance symmetrically, and skips closed geometry automatically.
Key Workflow Advantages
Dual-Endpoint Extension: Extends both ends of selected objects simultaneously in one execution pass.
Batch Line Processing: Select an entire cluster of grid lines or centerlines with a crossing window to extend them all at once.
Smart Distance Memory: Remembers your last used extension distance so you can press Enter for fast, repetitive updates.
Closed Object Safeguard: Automatically ignores closed polylines, circles, or rectangles to prevent unwanted geometry errors.
Step-by-Step Instructions
Load
EXD.lspin AutoCAD using theAPPLOADcommand.Type
EXDin the command prompt and press Enter.Specify your target extension distance (or press Enter to accept your previously saved distance).
Select the lines or open polylines you want to extend.
Hit Enter to confirm. The script extends both ends of every selected entity and reports the total count in your command window.
AutoLISP Code (EXD.lsp)
Copy the code below and save it as EXD.lsp inside your AutoCAD support folder:
(defun C:EXD ( / doc olderr oldecho oldosmode tmp ss i ent startPt endPt )
(vl-load-com)
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq olderr *error*)
(defun *error* (msg)
(if doc (vla-EndUndoMark doc))
(if oldecho (setvar "CMDECHO" oldecho))
(if oldosmode (setvar "OSMODE" oldosmode))
(setq *error* olderr)
(princ "\nCAD Lisp [www.daolpro.com]")
(princ)
)
(setq oldecho (getvar "CMDECHO"))
(setq oldosmode (getvar "OSMODE"))
(setvar "CMDECHO" 0)
(if (not *ex-dist*) (setq *ex-dist* 100.0))
(setq tmp (getdist (strcat "\nSpecify extension distance <" (rtos *ex-dist*) ">: ")))
(if tmp (setq *ex-dist* tmp))
(vla-StartUndoMark doc)
(setvar "OSMODE" 0)
(setq ss (ssget '((0 . "LINE,LWPOLYLINE,POLYLINE"))))
(if ss
(progn
(setq i 0)
(while (< i (sslength ss))
(setq ent (ssname ss i))
(if (not (vlax-curve-isClosed ent))
(progn
(setq startPt (vlax-curve-getStartPoint ent))
(setq endPt (vlax-curve-getEndPoint ent))
(command "_.LENGTHEN" "_DE" *ex-dist* (list ent startPt) (list ent endPt) "")
)
)
(setq i (1+ i))
)
(princ (strcat "\n[Success] " (itoa (sslength ss)) " object(s) extended by " (rtos *ex-dist*) " on both sides."))
)
(princ "\n[Cancelled] No lines selected.")
)
(vla-EndUndoMark doc)
(setvar "CMDECHO" oldecho)
(setvar "OSMODE" oldosmode)
(setq *error* olderr)
(princ "\nCAD Lisp [www.daolpro.com]")
(princ)
)
Practical Drafting Application
Use EXD.lsp when preparing architectural grids to extend grid bubbles out past external building walls or when setting up dimension projection lines across structural floor plans.

Post a Comment