Hi there;
I have just read through the ATP 67 notes by Peter and trying to write a code for a routine to select a closed lwpolyline and then automatically select all lines within the lwpolyline and calculate the intersection points.I am now trying to write a selection function using VL method but am facing an error which I could not solve. The attached code has an error in the program line "(print " d")(princ newsset)" when executed. Could anyone please enlighten me on this as I followed this code from Afralisp tutorial. Another question is that, how can we get the intersection points of the lwpolyline and the line if the lwpolyline and the line have different z- elevation values? It seems the method intersectwith is only valid for 2D values . Please enlighten.
Code:
;
;subroutine dxf
(defun dxf (code ename)
(cdr (assoc code (entget ename)))
); dxf
;;================================================ ===========
;; C:WG-MP Routine to calculate area of sublots by picking only a closed LWpolyline
;;
(defun C:WG-MP ( / 2pi e coords ss Total object)
(vl-load-com)
(setvar "errno" 0)
(setq 2pi (* pi 2))
(while (/= (getvar "errno") 52)
(cond
((setq coords (@polydir (setq e (car (entsel "\nSelect a polyline: ")))))
(if coords
(progn
(print "here1")
(entdel e)
(print "coords ")(princ coords)
;using autolisp method
(setq ss (ssget "CP" coords (quote ((0 . "LINE")))))
(entdel e)
(if ss
(progn
(setq Total (sslength ss))
(setq IntersectionPts-List (WG_VL-get-intersection-pts Total))
);progn ss
);if ss
);progn coords
);if coords
(prompt " using VL method")
;using VL method
(selectionVL)
(print "selectionsets ")(princ selectionsets)
); 1st condition
);cond
);while
(princ)
);polydir
; To select objects using VL method
(defun selectionVL()
(setq activedocumentObj(vla-get-activedocument(vlax-get-acad-object)))
(setq ssets (vla-get-selectionsets activedocumentObj))
(setq newsset (vla-add ssets "SS1"))
(print "d")(newsset)
(setq filter_code (vlax-make-safearray vlax-vbinteger '(0.0)))
(setq filter_value (vlax-make-safearray vlax-vbvariant '(0.0)))
(vlax-safearray-fill filter_code '(0))
(vlax-safearray-fill filter_value '("LINE"))
(vla-selectONscreen newsset filter_code filter_value)
(vla-delete(vla-item ssets "SS1"))
);selectionVL
(defun WG_VL-get-intersection-pts(Total / object2 iPts Pts L xy1 xy2)
(setq L 0)
(while (< L Total)
(setq object2 (vlax-ename->vla-object
(ssname ss L)
)
; xy1 (vla-get-Coordinates object2)
; xy2 (vla-get-EndPoint object2)
; find intersection of objects
iPts (vla-intersectwith object object2 0)
iPts (vlax-variant-value iPts)
);setq
;(print "xy1 ")(princ xy1)
;(print "xy2 ")(princ xy2)
(if (> (vlax-safearray-get-u-bound iPts 1) 0)
(progn
(setq iPts (vlax-safearray->list iPts))
(while (> (length iPts) 0)
(setq Pts (cons (list (car iPts)(cadr iPts)(caddr iPts)) Pts)
iPts (cdddr iPts)
)
);while
);progn
);if
(setq L (1+ L))
);while < L total
Pts
);WG_VL-get-intersection-pts
;;-----------------------------------------------------------------------
;; 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)
);@delta
;;-------------------------------------------------------------
;; 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
); @cv_parse_list
(defun @polydir (e / ent etype flag i p1 p2 p3 sum)
(cond
((/= (type e) 'ENAME)
nil
)
((not (vl-position (setq etype (dxf 0 e))
'("LWPOLYLINE")))
(prompt (strcat " Object selected is a(n) " etype))
)
((and (setq flag (dxf 70 e))(> (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")
(if (minusp sum) coords (reverse coords))
);1
);cond
);@polydir
Thanks
csgoh
5-3-05