CADLISPMASTER
Stop wasting time on repetitive AutoCAD tasks. CAD LISP Master provides free, efficient AutoLISP codes and clear tutorials designed to automate your workflow and speed up your drafting.

Extend Lines on Both Sides Instantly

Free AutoCAD LISP to extend lines and polylines on both sides instantly. Download EXD.lsp to speed up your CAD drafting.

 [AutoCAD LISP] Extend Lines on Both Sides Instantly (EXD.lsp)

Extend Lines on Both Sides Instantly
When drafting in AutoCAD, you frequently need to extend lines or polylines equally on both sides to clear margins, create centerlines, or adjust structural layouts. Doing this manually—either by clicking grips, using the LENGTHEN command with the Delta option twice per line, or drawing temporary offset lines—is incredibly tedious and a massive waste of time.

If you have dozens of lines to modify, this repetitive task slows down your workflow and opens the door to human error. That is why automating this process with a dedicated routine is essential for any professional drafter looking to maintain speed and accuracy.

Why You Should Use the 'EXD' LISP

  • Effortless Dual Extension: Extends both ends of lines or open polylines simultaneously with a single command.
  • Massive Time Saver: Eliminates the need to click individual grips or repeat commands for each side of a line.
  • Batch Processing Power: Select multiple lines at once and extend them all instantly by your specified distance.
  • Smart Memory Feature: It remembers your last used extension distance, allowing for rapid-fire execution without re-typing values.

How It Works (Step-by-Step Guide)

  1. Load the LISP File: Load the EXD.lsp file into AutoCAD using the APPLOAD command.
  2. Run the Command: Type EXD in the command line and press Enter.
  3. Set the Distance: The prompt will ask you to specify the extension distance. It will display your last used value as the default. Type a new distance or just press Enter to accept the current one.
  4. Select Objects: Select the lines, polylines, or lightweight polylines you want to extend. (Note: Closed shapes like circles or rectangles will automatically be skipped to prevent errors).
  5. Instant Execution: Press Enter to finish the selection. The LISP will instantly extend all chosen objects from both ends and display a success message showing how many objects were updated.

Wrapping Up

The EXD LISP is a straightforward yet powerful utility designed to remove one of the most annoying micro-tasks in AutoCAD drafting. By reducing a multi-step click routine into a seamless select-and-go process, you can keep your momentum and focus on what truly matters in your design.

Here’s a LISP you can add to your startup suite. It’ll save you a ton of time today. Let me know if you run into any bugs.

The LISP Code

(defun C:EXD ( / doc ss i ent startPt endPt oldecho tmp )
  (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (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))
  (setq ss (ssget '((0 . "LINE,LWPOLYLINE,POLYLINE"))))
  (if ss
    (progn
      (setq oldecho (getvar "CMDECHO"))
      (setvar "CMDECHO" 0)
      (vla-StartUndoMark doc)
      (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))
      )
      (vla-EndUndoMark doc)
      (setvar "CMDECHO" oldecho)
      (princ (strcat "\n[Success] " (itoa (sslength ss)) " object(s) extended by " (rtos *ex-dist*) " on both sides."))
    )
    (princ "\n[Cancelled] No lines selected.")
  )
  (princ)
)

Post a Comment