parallel lines into a single line

Discussion in 'AutoCAD' started by jalw, May 27, 2005.

  1. jalw

    jalw Guest

    Found a script that will do the above but deletes the parallel lines.
    I have tried to make it run without deleting the lines but nothing
    has worked.
    Any help is appreciated.

    (defun avg2 (a b)
    (/ (+ a b) 2.0))

    ;;singln - Replaces parallel lines with a single line.
    (defun c:singln ( / ss e1 e2 ei ei2 p1 p2 p3 p4)
    (and
    (princ "\nSelect 2 parallel lines: ")
    (setq ss (ssget (list (cons 0 "line"))))
    (setq e1 (ssname ss 0))
    (setq e2 (ssname ss 1))
    (setq ei (entget e1))
    (setq ei2 (entget e2))
    (setq p1 (cdr(assoc 10 ei)))
    (setq p2 (cdr(assoc 11 ei)))
    (setq p3 (cdr(assoc 10 ei2)))
    (setq p4 (cdr(assoc 11 ei2)))
    (or
    (< (distance p1 p3)(distance p1 p4))
    (setq pt p3 p3 p4 p4 pt))
    (entmod
    (list
    (cons -1 e1)
    (cons 10 (mapcar 'avg2 p1 p3))
    (cons 11 (mapcar 'avg2 p2 p4))))
    (entdel e2))
    (princ))
     
    jalw, May 27, 2005
    #1
  2. jalw

    mike.grutter Guest

    Using the ENTMAKE function in place of the ENTMOD/ENTDEL functions will
    place a third line between your parallel lines. Simply comment out the
    lines from (entmod... to ...entdel e2)) and insert the (entmake
    function. You'll have to gather more information from the original
    selection set (e1 or e2) to have available the minimum values to create
    the new entity. Consult the AutoLISP Reference in ACAD help for the
    required information to create the entity.

    Actually, this routine doesn't require the lines to be parallel. It
    will place a LINE entity from the midpoint between the start point to
    the midpoint between the end point of your two selections regardless of
    length or angle.
     
    mike.grutter, May 31, 2005
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.