Try this:
- (defun C:test ( / ErrCatcher BlksColl SS i o cnt flg nm ); (ErrCatcher 'vla-item (list (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) "BlockThatDoesNotExist")) -> nil(defun ErrCatcher ( func varLst / rtn ) (if (not (vl-catch-all-error-p (setq rtn (vl-catch-all-apply func varLst)))) rtn))(setq BlksColl (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))(prompt "\nSelect blocks to convert them into static ones:" )(if (setq SS (ssget "_:L" (list (cons 0 "INSERT")))) (repeat (setq i (sslength SS)) (if (eq :vlax-true (vla-get-IsDynamicBlock (setq o (vlax-ename->vla-object (ssname SS (setq i (1- i))))))) (progn (setq cnt 0) (setq flg 'T) (while flg (if (not (ErrCatcher 'vla-item (list BlksColl (setq nm (strcat (vla-get-EffectiveName o) "_" (itoa (setq cnt (1+ cnt)))))))) (progn (vla-ConvertToStaticBlock o nm) (setq flg nil)) ); if ); while ); progn ); if ); repeat); if(princ));| defun |; (or vlax-get-acad-object (vl-load-com)) (princ)
Note that the original dynamic blocks are not purged. |