@s.nijdam hi,
check this RSB command. it let you Rename Selected Blocks.
it refers to the space character (or any other that might be there) as TOKEN and substitute it with another token.
for example in your case you want to eliminate spaces so i declare these constants:
(setq SOR-TOKEN " ") ; one space
to be substitute with
(setq TAR-TOKEN "") ; no space
by setting these 2 constant variables you can control the blocks rename very easily. like changing from "_" to "-" and visa versa. remember that after you eliminate any tokens you want be able to change it back except for undo.
at end you will get a report of successful (or failed) rename.
enjoy
moshe
(vl-load-com)
; Rename Selected Blocks (replace tokens)
(defun c:RSB (/ subst-tokens ; local function
SOR-TOKEN TAR-TOKEN blocks ss sorBN tarBN AcDbBlkRef AcDbBlkTblRec)
; substitute tokens
(defun subst-tokens (str)
(while (vl-string-search SOR-TOKEN str)
(setq str (vl-string-subst TAR-TOKEN SOR-TOKEN str))
)
str
); subst-tokens
; here start (c:RSB) command
(setq SOR-TOKEN " "
TAR-TOKEN "") ; const
(setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(if (setq ss (ssget '((0 . "insert"))))
(foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
(setq AcDbBlkRef (vlax-ename->vla-object ename))
(setq sorBN (vla-get-effectiveName AcDbBlkRef))
; does renamed block can be applied?
(if (null (tblsearch "block" (setq tarBN (subst-tokens sorBN))))
(progn
(setq AcDbBlkTblRec (vla-item blocks sorBN))
(vla-put-name AcDbBlkTblRec tarBN)
(vlax-release-object AcDbBlkTblRec)
(prompt (strcat "\nblock \"" sorBN "\" Rename to \"" tarBN "\"."))
); progn
(prompt (strcat "\nblock \"" sorBN "\" Failed to rename to \"" tarBN "\"."))
); if
(vlax-release-object AcDbBlkRef)
); foreach
); if
(vlax-release-object blocks)
(textscr)
(princ)
); c:RSB