parallel-processinglineautocadautolisp

Draw Line Connecting Ends of 2 Parallel Lines with AutoLisp


does anyone have an AutoLisp routine to quickly draw a line connecting two parallel lines. I would really like something that works similar to the fillet command, except drawing a straight line instead of a radius. This could almost be accomplished with the chamfer command, except chamfer does not work with parallel lines.

My job sometimes consists of offsetting a lot of pairs of parallel lines and then connecting them with another line to create rectangles. It is easy enough to just draw a line between them, but it is still a tedious process.


Solution

  • (defun c:connectLines (/ line1 line2 data1 data2 pt1 pt2 pt3 pt4)
      (and
        (setq line1 (car (entsel "\nSelect first line: ")))
        (= (cdr (assoc 0 (setq data1 (entget line1)))) "LINE")
        (setq line2 (car (entsel "\nSelect second line: ")))
        (= (cdr (assoc 0 (setq data2 (entget line2)))) "LINE")
        (setq pt1 (cdr (assoc 10 data1))
              pt2 (cdr (assoc 11 data1))
              pt3 (cdr (assoc 11 data2))
              pt4 (cdr (assoc 10 data2))
        )
        (or (< (distance pt2 pt3) (distance pt2 pt4))
            (mapcar 'set '(pt3 pt4) (list pt4 pt3))
        )
        (command "_.erase"
                 (ssadd line2 (ssadd line1))
                 ""
                 "_.pline"
                 "_non"
                 (trans pt1 0 1)
                 "_non"
                 (trans pt2 0 1)
                 "_non"
                 (trans pt3 0 1)
                 "_non"
                 (trans pt4 0 1)
                 "_close"
        )
      )
      (princ)
    )