Here's another approach -
(defun c:test ( / elv ent enx )
(cond
( (not (setq ent (car (entsel)))))
( (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
(princ "\nObject is not a polyline.")
)
( t
(setq elv (list (cdr (assoc 38 enx))))
(foreach x (getcorners ent)
(entmake (list '(0 . "POINT") (cons 10 (trans (append x elv) ent 0))))
)
)
)
(princ)
)
(defun getcorners ( ent / enx lst pnt rtn )
(setq enx (entget ent)
lst (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx))
)
(if (< (length lst) 3)
lst
(progn
(setq rtn (list (cadr lst) (car lst))
lst (cddr lst)
)
(while (setq pnt (car lst))
(while (and (cadr rtn) (LM:collinear-p pnt (car rtn) (cadr rtn)))
(setq rtn (cdr rtn))
)
(setq rtn (cons pnt rtn)
lst (cdr lst)
)
)
(setq rtn (reverse rtn))
(if (and (= 1 (logand 1 (cdr (assoc 70 enx))))
(LM:collinear-p (last rtn) (car rtn) (cadr rtn))
)
(setq rtn (cdr rtn))
)
rtn
)
)
)
;; Collinear-p - Lee Mac
;; Returns T if p1,p2,p3 are collinear
(defun LM:Collinear-p ( p1 p2 p3 )
(
(lambda ( a b c )
(or
(equal (+ a b) c 1e-8)
(equal (+ b c) a 1e-8)
(equal (+ c a) b 1e-8)
)
)
(distance p1 p2) (distance p2 p3) (distance p1 p3)
)
)
(princ)