Originally Posted by
fa_veneno23141159
It's your routine tedg.
This routine is exactly I need. Help me , please...
Thanks
As Chris Cowgill suggested, removing the ":S" from the code will allow you to window many different blocks.
However.. you need to select the "Single" option if you're changing all the selected different blocks to one type of block.
If you choose "Global" it will only change one type of block in your selection to the other block you choose.
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 '((0 . "INSERT"))));;REMOVED THE :S
(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)
)