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.

AutoCAD Infinite Line Tool: Draw & Purge Custom-Angle Construction Lines

Draw parallel infinite lines at any angle and purge them in one click in AutoCAD using FEX.lsp. Free AutoLISP script for clean layout drafting.

[CAD LISP] Create Continuous Custom-Angle Infinite Lines and Clean Them Up Instantly

Create Infinite Line

Setting up angled grid lines, projecting structural points, or establishing reference baselines in AutoCAD usually relies on the standard XLINE command. However, setting custom angles repeatedly forces you to re-enter values continuously. Even worse, once your layout is complete, your drawing becomes cluttered with infinitely extending lines that are tedious to clean up manually.

The FEX.lsp (Fast Extension Line) routine turns construction line setup into a smooth, continuous workflow. Simply pick two points to set your target angle once, and click anywhere to place aligned reference lines indefinitely. When your drafting is finished, enter the X option to automatically sweep away all FEX construction lines in a single click.


Key Workflow Highlights

  • One-Time Angle Definition: Specify your target angle once by picking two reference points on screen—no need to re-enter angle values for subsequent lines.

  • Continuous Placement: Click anywhere across your drawing canvas to drop perfectly parallel reference lines instantly.

  • Instant One-Click Purge: Type X during command setup to automatically detect and delete every infinite line created by the script, keeping your workspace clean.

  • Controlled Line Length: Generates ultra-long, 10,000,000-unit lines instead of true infinite entities to prevent display glitches while maintaining easy tracking for deletion.


Step-by-Step Instructions

  1. Load FEX.lsp in AutoCAD using the APPLOAD command.

  2. Type FEX in the command prompt and hit Enter.

  3. To place new lines:

    • Click your first point, then click a second point to establish your target angle.

    • Click anywhere on screen to place construction lines passing through those points.

    • Press Enter or Spacebar when finished to reset the angle or exit.

  4. To purge construction lines:

    • Type X (or x) at the initial prompt and press Enter. All FEX lines will be deleted immediately.


AutoLISP Code (FEX.lsp)

Copy the code below and save it as FEX.lsp inside your AutoCAD support folder:

(defun c:FEX ( / *error* acDoc oldecho run pt1 pt2 ang pt3 ss i ent dxf len )
  (vl-load-com)
  (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq oldecho (getvar "CMDECHO"))
  
  (defun *error* (msg)
    (if oldecho (setvar "CMDECHO" oldecho))
    (vla-EndUndoMark acDoc)
    (princ "\nCAD Lisp [www.daolpro.com]")
    (princ)
  )
  
  (setvar "CMDECHO" 0)
  (vla-StartUndoMark acDoc)
  
  (setq run t)
  (while run
    (initget "X x")
    (setq pt1 (getpoint "\nSpecify first point for angle or [Delete infinite lines(X)]: "))
    (cond
      ((or (= pt1 "X") (= pt1 "x"))
       (if (setq ss (ssget "X" '((0 . "LINE"))))
         (progn
           (setq i (sslength ss))
           (while (> i 0)
             (setq i (1- i)
                   ent (ssname ss i)
                   dxf (entget ent)
                   len (distance (cdr (assoc 10 dxf)) (cdr (assoc 11 dxf))))
             (if (equal len 10000000.0 0.1)
               (entdel ent)
             )
           )
           (princ "\nSuccess: All infinite lines deleted.")
         )
         (princ "\nError: No lines found.")
       )
       (setq run nil)
      )
      ((listp pt1)
       (setq pt2 (getpoint pt1 "\nSpecify second point for angle: "))
       (if pt2
         (progn
           (setq ang (angle pt1 pt2))
           (while (setq pt3 (getpoint "\nSpecify point to place line (Press Enter to change angle): "))
             (entmake (list '(0 . "LINE") 
                            (cons 10 (polar pt3 ang 5000000.0)) 
                            (cons 11 (polar pt3 (+ ang pi) 5000000.0))))
           )
         )
         (setq run nil)
       )
      )
      (t (setq run nil))
    )
  )
  
  (vla-EndUndoMark acDoc)
  (if oldecho (setvar "CMDECHO" oldecho))
  (princ "\nCAD Lisp [www.daolpro.com]")
  (princ)
)

Layout Efficiency Tip

Because FEX.lsp identifies its construction lines by exact length (10,000,000 units), you don't have to worry about accidentally deleting standard project lines when running the X purge option.

Post a Comment