试试这个:
- (defun c:dx (/ blk e el name ss x)
- (defun _ss->list (ss / n out)
- (if (= (type ss) 'pickset)
- (repeat (setq n (sslength ss)) (setq out (cons (ssname ss (setq n (1- n))) out)))
- )
- )
- (while
- (and (setq e (car (entsel "\nSelect Reference to Detach: ")))
- (setq el (entget e))
- (= (cdr (assoc 0 el)) "INSERT")
- (setq name (cdr (assoc 2 el)))
- (setq blk (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) name))
- (minusp (vlax-get blk 'isxref))
- (setq ss (_ss->list (ssget "_x" (list (cons 2 name)))))
- )
- (if (= (length ss) 1)
- (vl-catch-all-apply 'vla-detach (list blk))
- (progn
- (foreach xr (mapcar 'vlax-ename->vla-object ss) (vl-catch-all-apply 'vla-delete (list xr)))
- (vl-catch-all-apply 'vla-detach (list blk))
- )
- )
- )
- (princ)
- )
|