Well, since no one helped you all day long......
Here's something that is nearly complete. I'll leave it to you to play with and improve/modify to suit:
Code:
(defun c:blkreplacer (/ answr ent idx newname obj ss)
(vl-load-com)
;;setup default on first run
(if (not jmm-replaceall)
(setq jmm-replaceall "Single")
)
(command ".undo" "be")
;;if the user selects something, inputs a ne block name AND it exists in the dwg...
(if (and (setq ss (ssget ":S" '((0 . "INSERT"))))
(progn
(initget "Single Global")
(if (setq answr (getkword "\nReplace just this block or Globally replace?[Single/Global]: "))
(setq jmm-replaceall answr)
(setq answr jmm-replaceall)
)
)
(setq newname (getstring "\nBlock name to replace with: "))
(tblobjname "BLOCK" newname)
)
(progn
(if (eq jmm-replaceall "Global");;get ALL occurances if it's Global, else use the original ss
(setq ss (ssget "x" (list '(0 . "INSERT") (assoc 2 (entget (ssname ss 0))))))
)
(setq idx -1)
(while (setq ent (ssname ss (setq idx (1+ idx))))
(setq obj (vlax-ename->vla-object ent))
(vla-put-name obj newname);;change the name
(vla-update obj)
)
)
)
(command ".undo" "end")
(princ (strcat "\nReplaced " (itoa idx) " blocks......"))
(princ)
)
Note that this may not work as expected with attributed blocks! If you need that functionality, I leave that for you to investigate
Jeff