Author Topic: nested polygon report  (Read 1616 times)

0 Members and 1 Guest are viewing this topic.

Vandyck

  • Newt
  • Posts: 24
nested polygon report
« 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
Code: [Select]
(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")

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: nested polygon report
« Reply #1 on: May 29, 2015, 10:03:03 AM »

Vandyck

  • Newt
  • Posts: 24
Re: nested polygon report
« Reply #2 on: May 29, 2015, 11:53:14 AM »
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.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: nested polygon report
« Reply #3 on: May 29, 2015, 12:59:28 PM »
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).