TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Vandyck on May 29, 2015, 09:39:55 AM
-
Hi all
I'm writing a routine to report nested polygon status in a drawing. Every polygon/pline are organized on layers (see image and dwg attached)
About the attached image My intent is obtain a report like this:
- 1 POLYLINE ON LEVEL 'level_1'
- 2 POLYLINE ON LEVEL 'level_2'
- 1 POLYLINE ON LEVEL 'level_3'
- 2 POLYLINE ON LEVEL 'level_4'
- 1 POLYLINE ON LEVEL 'level_5'
- 1 POLYLINE ON LEVEL 'level_3'
- 2 POLYLINE ON LEVEL 'level_4'
for each container write its contents.
But the effective output of my code is this:
- 1 POLYLINE ON LEVEL 'level_1'
- 2 POLYLINE ON LEVEL 'level_2'
- 1 POLYLINE ON LEVEL 'level_3'
- 2 POLYLINE ON LEVEL 'level_4'
- 1 POLYLINE ON LEVEL 'level_3'
- 2 POLYLINE ON LEVEL 'level_4'
Where is 1 pline on 'level_5' ? ? ?
There is something wrong in my code.
Anyone has any idea or an alternative method?
this is the code
(DEFUN C:TEST ()
;| FIND_POLYGON |;
;; SEARCH POLYGON IN SS SELECTION SET ON "LEVEL_NAME" LAYER
(defun FIND_POLYGON ( Ss LEVEL_NAME / ss2 VERTEX w NEXT_LEVEL )
(PROMPT (STRCAT "\n-" (Tab LEVEL_NAME) (itoa(SSLENGTH SS)) " POLYLINE ON LEVEL '" LEVEL_NAME "'"))
(setq NEXT_LEVEL(nth 1 (MEMBER LEVEL_NAME LEVEL_LIST)))
(if NEXT_LEVEL
(progn
(setq w 0 )
(repeat (SSLENGTH SS) ;
;; GET VERTEX ON PLINE TO MAKE A CROSSIN POLIGON SELECTION
(setq VERTEX(pso(ssname ss w) 50))
;; GET INNER PLINE OM THE NEXT LEVEL (LAYER)
(setq ss2(ssget "_cp" vertEX (list (cons 0 "*POLYLINE")(cons 8 NEXT_LEVEL))))
(if ss2
(FIND_POLYGON ss2 NEXT_LEVEL)
)
(setq w(1+ w))
)
)
(PROGN
;(setq tab (substr tab 1 (1- (strlen tab))))
NIL
)
)
)
;| tab |;
;; SET NUMbER of tabulation "\t" string to format output
(DEFUN TAB ( V / &TAB)
(SETQ &TAB "")
(REPEAT (1+(VL-POSITION V LEVEL_LIST))
(SETQ &TAB (STRCAT "\t" &TAB ))
)
&TAB
)
;| PSO |;
;; Points on object
;; return points list along the object
;; e = <ename>
;; N = <REAL> subdivision
(defun PSO (e n / l v d lst)
(setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam
e (vlax-curve-getEndParam e))) n))
)
)
(while (< (setq d (+ d v)) l)
(setq lst (cons (vlax-curve-getPointAtDist e d) lst))
)
)
;------------------------------------------------------------------------------------------
(SETQ LEVEL_LIST '("level_1""level_2""level_3""level_4""level_5" ))
;; GET OUTSIDE LEVEL POLYGON
(setq ss:as(ssget "_A" (list (cons 0 "*POLYLINE")(cons 8 (nth 0 LEVEL_LIST)))))
;; ROUTINe TO SEARCH NESTED POLYGON STARTING FROM OUTSIDE
(FIND_POLYGON ss:as (nth 0 LEVEL_LIST))
(princ)
)
(prompt"\nType TEST")
-
See this thread:
http://www.theswamp.org/index.php?topic=44566.0
-
thanks for the tip Lee, but the code in the thread is only about rectangles :-( . I used rectangles to simplify the question, but in reality I use irregular shapes with more than 4 vertices.
-
thanks for the tip Lee, but the code in the thread is only about rectangles :-( . I used rectangles to simplify the question, but in reality I use irregular shapes with more than 4 vertices.
After a cursory review of the code posted in that thread, I believe the examples should also perform reasonably well for irregular polygons (those that are convex at least).