TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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:
(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 ...
-
EDIT: - Solved. Found code here
http://www.cadtutor.net/forum/showthread.php?12647-Getting-a-list-of-groups-used-in-autocad
-
; 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)
)