Make single line from parallel lines w/o deleting lines

Discussion in 'AutoCAD' started by jwbike, Feb 5, 2007.

  1. jwbike

    jwbike Guest

    Have a script that makes a single line from parallel lines and then
    deletes the parallel lines.
    I have tried to modify it to where the parallel lines do not delete
    but I'm getting nowhere.
    Any suggestions as to modify the script to not delete the lines?
    Please show what the code
    is when explaining the solution.

    (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))
     
    jwbike, Feb 5, 2007
    #1
  2. jwbike

    Paul Turvill Guest

    Change
    (entmod
    to
    (entmake

    then delete
    (entdel e2)
    ....but leave the last ")" in that line.
    ___
     
    Paul Turvill, Feb 5, 2007
    #2
  3. jwbike

    jwbike Guest

    Didn't work and there wasn't any error messages when I tried it.
     
    jwbike, Feb 5, 2007
    #3
  4. jwbike

    TH arcor Guest

    This works:

    (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)
    )

    (entmake
    (list
    (cons 0 "LINE")
    ; (cons -1 e1)
    (cons 10 (mapcar 'avg2 p1 p3))
    (cons 11 (mapcar 'avg2 p2 p4))))
    ;(entdel e2)
    )
    (princ)
    )


    (defun avg2 (a b)
    (/ (+ a b) 2.0))
     
    TH arcor, Feb 6, 2007
    #4
  5. jwbike

    Paul Turvill Guest

    Good catch. My mods still tried to carry over the "e1" entity name.
    ___
     
    Paul Turvill, Feb 6, 2007
    #5
  6. jwbike

    jwbike Guest

    Awesome! Thank you for the help!
     
    jwbike, Feb 7, 2007
    #6
  7. What do you type to run the lisp?

    JPC
     
    John Callaway, Feb 9, 2007
    #7
  8. jwbike

    Thomas Guest

    After loading the lispfile on the command-level:

    singln

    then the command starts and prompts
    for selecting two lines.

    hth

    Thomas
     
    Thomas, Feb 11, 2007
    #8
  9. Thanks!

     
    John Callaway, Feb 16, 2007
    #9
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.