TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Peter2 on July 21, 2016, 05:26:43 AM

Title: Group - empty or not?
Post by: Peter2 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 ...
Title: Re: Group - empty or not?
Post by: Peter2 on July 21, 2016, 05:47:21 AM
EDIT: - Solved. Found code here
http://www.cadtutor.net/forum/showthread.php?12647-Getting-a-list-of-groups-used-in-autocad
Title: Re: Group - empty or not?
Post by: Marc'Antonio Alessi 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)
)