draw lines at endpoint

draw lines at endpoint

nychoe1
Advocate Advocate
989 Views
4 Replies
Message 1 of 5

draw lines at endpoint

nychoe1
Advocate
Advocate

there are many lines and

I have to draw lines at each line's endpoint.

 

is there any lsp and any ideas?

 

have to attached dwg file, thank you for reading.  I need to help please

 

funny AutoCAD...!!!

0 Likes
990 Views
4 Replies
Replies (4)
Message 2 of 5

CADaSchtroumpf
Advisor
Advisor

Try with this?

((lambda ( / js n dxf_ent p10 p11 alpha)
  (princ "\nSelect line: ")
  (setq js (ssget '((0 . "LINE"))))
  (cond
    (js
      (repeat (setq n (sslength js))
        (setq
          dxf_ent (entget (ssname js (setq n (1- n))))
          p10 (cdr (assoc 10 dxf_ent))
          p11 (cdr (assoc 11 dxf_ent))
          alpha (angle p10 p11)
        )
        (entmake
          (list
            (assoc 0 dxf_ent)
            '(100 . "AcDbEntity")
            (assoc 67 dxf_ent)
            (assoc 410 dxf_ent)
            (assoc 8 dxf_ent)
            (if (assoc 62 dxf_ent) (assoc 62 dxf_ent) '(62 . 256))
            (if (assoc 6 dxf_ent) (assoc 6 dxf_ent) '(6 . "BYLAYER"))
            (if (assoc 48 dxf_ent) (assoc 48 dxf_ent) '(48 . 1.0))
            (if (assoc 370 dxf_ent) (assoc 370 dxf_ent) '(370 . -1))
            '(100 . "AcDbLine")
            (cons 10 (polar p10 (+ alpha (* pi 0.5)) 250.0))
            (cons 11 (polar p10 (- alpha (* pi 0.5)) 250.0))
            (assoc 210 dxf_ent)
          )
        )
        (entmake
          (list
            (assoc 0 dxf_ent)
            '(100 . "AcDbEntity")
            (assoc 67 dxf_ent)
            (assoc 410 dxf_ent)
            (assoc 8 dxf_ent)
            (if (assoc 62 dxf_ent) (assoc 62 dxf_ent) '(62 . 256))
            (if (assoc 6 dxf_ent) (assoc 6 dxf_ent) '(6 . "BYLAYER"))
            (if (assoc 48 dxf_ent) (assoc 48 dxf_ent) '(48 . 1.0))
            (if (assoc 370 dxf_ent) (assoc 370 dxf_ent) '(370 . -1))
            '(100 . "AcDbLine")
            (cons 10 (polar p11 (+ alpha (* pi 0.5)) 250.0))
            (cons 11 (polar p11 (- alpha (* pi 0.5)) 250.0))
            (assoc 210 dxf_ent)
          )
        )
      )
    )
  )
  (prin1)
))
Message 3 of 5

nychoe1
Advocate
Advocate
oh thank you
It's good working.
0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant

Here's a more consolidated way of doing it.  Instead of explicitly putting into each new end Line's data the necessary parts of the data from the Line it's drawn across an end of, and to eliminate the need to check whether it has any overrides of color, linetype, etc., so the new Lines will include those, you can just keep all of that in making the new end Lines, and simply give them new endpoints.  And you can spell out the across-the-end Line definition once, and apply it at both ends of each existing Line.  Lightly tested:

 

(defun C:EndLines (/ liness ldata ang)
  (prompt "\nTo draw 500-unit Lines across ends of existing Lines,")
  (if (setq liness (ssget '((0 . "LINE"))))
    (repeat (setq n (sslength liness))
      (setq
        ldata (entget (ssname liness (setq n (1- n))))
        ang (angle (cdr (assoc 10 ldata)) (cdr (assoc 11 ldata)))
      ); setq
      (foreach dxf '(10 11)
        (entmake
          (append
            (vl-remove-if '(lambda (x) (member (car x) '(10 11))) ldata)
              ; everything except endpoints, including any optional overrides
            (list ; new endpoints
              (cons 10 (polar (cdr (assoc dxf ldata)) (+ ang (/ pi 2)) 250))
              (cons 11 (polar (cdr (assoc dxf ldata)) (- ang (/ pi 2)) 250))
            ); list
          ); append
        ); entmake
      ); foreach
    ); repeat
  ); if
  (princ)
); defun

It can also be done with even less code, by drawing one end Line, matching its properties to the existing one, and Copying it to the other end [all of those lumped together into one (command) function], but it's slower than the (entmake) approach:

 

(defun C:EndLines (/ liness line ldata ang p1 p2)
  (prompt "\nTo draw 500-unit Lines across ends of existing Lines,")
  (if (setq liness (ssget '((0 . "LINE"))))
    (repeat (setq n (sslength liness))
      (setq
        line (ssname liness (setq n (1- n)))
        ldata (entget line)
        ang (angle (setq p1 (cdr (assoc 10 ldata))) (setq p2 (cdr (assoc 11 ldata))))
      ); setq
      (command
        "_.line"
          "_none" (polar p1 (+ ang (/ pi 2)) 250)
          "_none" (polar p1 (- ang (/ pi 2)) 250)
          ""
        "_.matchprop" line (entlast) ""
        "_.copy" (entlast) "" "_none" p1 "_none" p2
      ); command
    ); repeat
  ); if
  (princ)
); defun

[By the way, in CADaStroumph's routine and either of mine, if the existing Lines might ever not lie in or parallel to the current construction plane, adjustments would be needed, because (polar) returns values in the current UCS.]

 

Kent Cooper, AIA
0 Likes
Message 5 of 5

jdiala
Advocate
Advocate

 

 

(defun C:test (/ ss i make2lines ang p1 p2 e )
(setq d 250) ;distance of line divide by 2
(defun make2lines (a b c) 
(entmake (list (cons 0 "LINE") (cons 10 (polar a (+ c (/ pi 2.)) d)) (cons 11 (polar a (- c (/ pi 2.)) d))))
(entmake (list (cons 0 "LINE") (cons 10 (polar b (+ c (/ pi 2.)) d)) (cons 11 (polar b (- c (/ pi 2.)) d))))
)
(if
(setq ss (ssget ":L" '((0 . "LINE"))))
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
      p1 (cdr (assoc 10 (entget e)))
      p2 (cdr (assoc 11 (entget e)))
      ang (angle p1 p2)
)
(make2lines p1 p2 ang)
)(princ "None selected!")
)(princ))  

 

0 Likes