Hi,
With dynamic blocks we have to select also all anonymous blocs ("`*U*") and then check if their "effective name" matches the searched block names.
Since AutoCAD 2012 we can use getpropertyvalue.
(defun c:demo (/ ss ent)
(if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 "`*U*,90-13,CE-13,1161B")))) ; Block names
(progn
(repeat (setq i (sslength ss))
(setq ent (ssname ss (setq i (1- i))))
(if
(not
(wcmatch (getpropertyvalue (getpropertyvalue ent "BlockTableRecord") "Name")
"90-13,CE-13,1161B" ; Block names
)
)
(ssdel ent ss)
)
)
(command "_.draworder" ss "" "_front")
)
)
(princ)
)
For pior versions, we can search deeply in the DXF lists
(defun c:demo (/ ss i elst)
(if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 "`*U*,90-13,CE-13,1161B")))) ; Block names
(progn
(repeat (setq i (sslength ss))
(setq elst (entget (ssname ss (setq i (1- i)))))
(if (and (wcmatch (cdr (assoc 2 elst)) "`*U*")
(not
(wcmatch (cdr
(assoc 2
(entget
(cdr
(assoc 340
(entget
(cdr
(assoc 360
(entget
(cdr
(assoc 360
(entget
(cdr
(assoc 360 elst)
)
)
)
)
)
)
)
)
)
)
)
)
)
"90-13,CE-13,1161B" ; Block names
)
)
)
(ssdel (cdr (assoc -1 elst)) ss)
)
)
(command "_.draworder" ss "" "_front")
)
)
(princ)
)