;;=========================================================== ;; PolyDir.LSP v1.0 (03-05-02) John F. Uhden, Cadlantic ;; This is freeware dedicated to Noah (?) and Cliff Middleton ;; (defun C:PolyDir ( / @delta @cv_parse_list @polydir 2pi e ans) ;;----------------------------------------------------------------------- ;; This function returns the deflection angle (in radians) of two angles: ;; (defun @delta (a1 a2) (cond ((> a1 (+ a2 pi)) (setq a2 (+ a2 2pi)) ) ((> a2 (+ a1 pi)) (setq a1 (+ a1 2pi)) ) ) (- a2 a1) ) ;;------------------------------------------------------------- ;; Function returns a list of 3D points from a continuous list ;; as returned by (vlax-safearray->list (vlax-variant-value X)) ;; (defun @cv_parse_list (data n / item new) (foreach element (reverse data) (setq item (cons element item)) (if (= (length item) n) (setq new (cons item new) item nil) ) ) new ) (defun @polydir (e / ent etype object coords flag i p1 p2 p3 sum) (cond ((/= (type e) 'ENAME) nil) ((not (vl-position (setq etype (cdr (assoc 0 (setq ent (entget e))))) '("AECC_CONTOUR" "LWPOLYLINE" "POLYLINE"))) (prompt (strcat " Object selected is a(n) " etype)) ) ((and (setq flag (cdr (assoc 70 ent)))(> (boole 1 16 flag) 0)) (prompt " Object selected is a 3DMESH") ) (1 (setq object (vlax-ename->vla-object e) coords (vlax-get object "Coordinates") coords (@cv_parse_list coords (if (= etype "LWPOLYLINE") 2 3)) i 1 sum 0.0 ) (and flag (= (logand 1 flag) 1) ; closed (setq coords (reverse (cons (car coords)(reverse coords)))) ) (repeat (- (length coords) 2) (setq p1 (nth (1- i) coords) p2 (nth i coords) i (1+ i) p3 (nth i coords) sum (+ sum (@delta (angle p1 p2)(angle p2 p3))) ) ) (if (minusp sum) "CW" "CCW") ) ) ) (setvar "errno" 0) (setq 2pi (* pi 2)) (while (/= (getvar "errno") 52) (if (setq ans (@polydir (setq e (car (entsel "\nSelect a polyline: "))))) (princ ans) ) ) (princ) )