Hi,
Here're some routines to create or delete anonymous groups.
PS: these groups appear as GRP1, GRP2, etc... instead of *A1, *A2, etc...
;; MAKEGROUP
;; Creates an anonymous group from an entity list
;;
;; Argument
;; lst : entity list (ename)
;;
;; Return
;; The created group (ename) or nil
(defun makegroup (lst / dict ind)
(setq dict (dictsearch (namedobjdict) "ACAD_GROUP")
ind "GRP1")
(while (member (cons 3 ind) dict)
(setq ind (strcat "GRP" (itoa (1+ (atoi (substr ind 4))))))
)
(dictadd
(cdr (assoc -1 dict))
ind
(entmakex
(append
(list
'(0 . "GROUP") '(100 . "AcDbGroup") '(300 . "") '(70 . 1) '(71 . 1))
(mapcar (function (lambda (x) (cons 340 x))) lst)
)
)
)
)
;; DELGROUP
;; Deletes all groups which the entity belongs to.
;;
;; Argument
;; ent : the entity name (ename)
;;
;; Return
;; The deleted groups list or nil
(defun delgroup (ent / ret)
(mapcar
(function
(lambda (p)
(and
(= (car p) 330)
(= (cdr (assoc 0 (entget (cdr p)))) "GROUP")
(setq ret (cons (entdel (cdr p)) ret))
)
)
)
(entget ent)
)
ret
)
;; PURGEGROUP
;; Deletes all empty groups
(defun purgegroup ()
(foreach g (mapcar 'cdr
(vl-remove-if-not
(function
(lambda (x) (= (car x) 350))
)
(dictsearch (namedobjdict) "ACAD_GROUP")
)
)
(or (assoc 340 (entget g)) (entdel g))
)
)
;; GRP
;; Creates a group with selected objects
(defun c:grp (/ ss n lst)
(and
(setq ss (ssget))
(repeat (setq n (sslength ss))
(setq lst (cons (ssname ss (setq n (1- n))) lst))
)
(makegroup lst)
)
(princ)
)
;; DGRP
;; Deletes all groups which the selected object belongs to.
(defun c:dgrp (/ ent)
(and
(setq ent (car (entsel)))
(delgroup ent)
)
(princ)
)