How to find the endpoint of polyline

2022-09-29
  • Detail

How to find the endpoint of polyline

;;;; Given a point in a polyline, find the front and rear end points of the point

(defun polyline_pt (ssn@ ptj@/PTZ PTS PTE JD jd1 JD2 ptb# pt##1 pt##2)

(pline_pt ssn@)

(if (= (setq fs (REM (CDR (Assoc'70 (entget ssn@))) 2)) 1)

.(setq ptb# (reverse (cons pt1##)

)

(setq LW (CDR (Assoc'40 (entget ssn@))

(setq PTZ (CDR (Assoc'38 (entget ssn@))

(setq PTS) (car ptb#) ptb## ptb#)

(setq ptb# (cdr ptb#))

(setq pt_1 nil pt_2 nil)

(setq ptj@ (trans ptj@ 1 0))

(while ptb#

(setq pte (car ptb#))

(setq jd (rem (angle pts pte) (* 2 pi)))

(if (equal jd (* 2 pi) 0.0001) (setq jd 0))

(setq jd1 (rem (angle pts ptj@) (* 2 pi)))

(if (equal jd1 (* 2 pi) 0.0001) (setq jd1 0))

(setq jd2 (rem (angle ptj@ pte) (* 2 pi)))

(if (equal jd2 (* 2 pi) 0.0001) (setq jd2 0))

(if (and (equal jd1 jd2 0.0001)(equal jd1 jd 0.0001))

(setq pt_1 pts pt_2 pte)

)

(setq pts pte)

(setq ptb# (cdr ptb#))

)

(if (and pt_1 pt_2)

(setq pt_1 (list (car pt_1) (car (cdr pt_1)) ptz)

pt_ 2 (list (car pt_2) (car (CDR pt_2)) PTZ))

(progn

(alert "cannot find the endpoints before and after the pick point!")

(exit)

)

)

)

;;;; ZDM2000

;;;; Looking for lwpolyline, Polyline point return point table ptb#

(defun pline_pt (ssn#/N Pt pt_b arc_b arcbz ssn5)

(s preparation of 13 national military standards etq SSB (entget ssn#) n 1 SSB1 SSB)

(if (= (CDR (Assoc'0 SSB)) "lwpolyline")

(progn

(while)(setq pt_b (Assoc'10 SSB))

(setq Pt (CDR pt_b))

(if (= n 1)

(setq pt1## Pt ptb# (list PT))

(the set situation is not very optimistic. Q pt2 \pt ptb (cons Pt ptb\)

)

(setq SSB (CDR (member pt_b SSB))

(setq n (+ n 1))

)

;;;;;; There is an extra point at the end of some closed lwpolyline, and the difference between this point and the first point is 0.001, which needs to be removed

;;;;;; In the compiled VLSP, lwpolyline points are 3D points, In AutoCAD, it is a two-dimensional point

(if (and (= (REM (CDR (Assoc'70 (entget ssn35;))) 2) 1) (equal pt1## pt2## 0.002))

(setq ptb# (reverse (CDR ptb#)) pt2## (car ptb#)

)

(setq n 1 SSB SSB1)

(while (setq arc_b (Assoc'42 SSB))

(setq arcbz (CDR arc_b))

(if (= n 1)

(setq arcb# (list arcbz))

(setq arcb# (cons arcbz arcb#)

)

(setq arcb# (cons arcbz arcb#)

(setq n (+ n 1))

)

)

(progn;; polyline

(setq ssn5 (entnext ssn35;)

(setq Pt (CDR (Assoc'10 (entget ssn5)))

(setq arcbz (CDR (Assoc'42 (entget ssn5)))

.

(integrate setq ptb# (list PT) pt1## Pt arcb# (list arcbz))

(setq ssn5 (entnext ssn5))

(while (/= (CDR (Assoc'0 (entget ssn5))) "sequence")

(setq Pt (CDR) (assoc '10 (entget ssn5))))

(setq arcbz (cdr (assoc '42 (entget ssn5))))

(setq ptb# (cons pt ptb# ) pt2## pt arcb# (cons arcbz arcb#))

(setq ssn5 (entnext ssn5))

)

)

)

(SETQ PTB# (REVERSE PTB#))

(setq arcb# (cons 0 (reverse arcb#)))

)

Copyright © 2011 JIN SHI