Author Topic: Group - empty or not?  (Read 1159 times)

0 Members and 1 Guest are viewing this topic.

Peter2

  • Swamp Rat
  • Posts: 650
Group - empty or not?
« on: July 21, 2016, 05:26:43 AM »
I need a way to define if a group (for example named "test") is empty or not.

I found a way to handle not-empty groups, but there are problems when they are empty:

Code: [Select]
(command "_.select" "_group" "test" "")
; -> returns always nil for empty and not-empty groups
(setq aws (ssget "_P"))
;-> Problem: "_P" are the elements of the not-empty group OR (if empty) some other "previous seöections"

I'm sure that there is a simple way which someone can show me ...
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Peter2

  • Swamp Rat
  • Posts: 650
Re: Group - empty or not?
« Reply #1 on: July 21, 2016, 05:47:21 AM »
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Group - empty or not?
« Reply #2 on: July 22, 2016, 07:45:56 AM »
Code: [Select]
; remove null groups and one entity groups too
; (ALE_Utl_PurgeGroups *AcAcDwg*)
;
(defun ALE_Utl_PurgeGroups (DbxDoc / VlaObj Countr)
  (setq Countr 0)
  (vlax-map-Collection
    (setq VlaObj (vla-get-groups DbxDoc))
   '(lambda (LmbDat)
      (or
        (< 1 (vla-get-count LmbDat))
        (progn
          (vla-delete LmbDat)
          (setq Countr (1+ Countr))
        )
      )
    )
  )
  (or
     (zerop Countr)
     (princ (strcat "\n" (itoa Countr) " unreferenced groups purged. "))
  )
  (vlax-release-object VlaObj)
)