Adds a prefix to all block names.
Hi, I'm looking for help to write a program that adds a prefix to all block names.
eg. I want to add '' SURVEY_ '' to the start of each block name, there could be a hundrets of blocks.
How to change a program to add a prefix to all blocks?
;;; Applies a prefix to all Layers in a Drawing except the 0 layer and Defpoints Layer ;;; (defun C:LP ( / acadDocument layertable layName prefix) (vl-load-com) (setq prefix(getstring "\nEnter Layer Prefix to Apply to All Layers: ")) (setq acadDocument (vla-get-activedocument (vlax-get-acad-object))) (setq layertable (vla-get-layers acadDocument)) (vlax-map-collection layertable 'layer-mod) (princ) ) (defun layer-mod (layertable) (setq layName (vlax-get-property layertable 'Name)) (if (not (member layName '("0" "Defpoints"))) (vla-put-Name layertable (strcat prefix layName)) ) ;endif )
Comments
-
You can use the built in -RENAME command for this. You can specify * for blocks to rename, rename them all to prefix*, then finally rename prefixDEFPOINTS back to just DEFPOINTS.
0 -
: -RENAME
The "-RENAME" command can not be resolved. Please try again.
I have basic versions and this command does not work for me.
The above code works for layers, but I do not know how to change it to change the names of blocks.
This code is not created by me.0 -
-RENAME should give you a command line option to choose what to rename, choose Block and it will ask you what block(s) should be rename.
(RENAME without the dash brings up the drawing explorer for renaming individual blocks one at a time)Make sure you type a dash (minus sign) and not an underscore before the command.
An example to explain how it works:
E.g. I have imported a drawing from another CAD program and some of its blocks are named Group-1, Group-2 etc. and want to add Survey- as a prefix to just those blocks instead of all blocks.Then the sequence should be:
-RENAME
[select block from the options on the command line]
Block to be renamed:
Enter Group*
you will then get: Block to be renamed: Group*
Hit enter and it will then list the blocks to be rename and you will see "New name:"
Type Survey-Group* and hit enter
Now it should rename all Group* blocks to Survey-Group-1, Survey-Group-2 etc.It is important to keep the Group* in the new name otherwise it will rename Group-1 to Survey--1.
If you want to add the same prefix to ALL blocks the only use * for the block name that has to get the prefix as @Owen Wengerd mentioned then it should create a prefix for all blocks to the new name as long as you you include * at the end of the prefix to keep the original name.
The -rename option should work in Bricscad Classic as well (I checked by setting my Platinum version to Classic via the RUNASLEVEL command).
I hope the above description gives you an idea of how the -RENAME command works.If it still does not work for you then you may want to file a support request.
0 -
If you are using a localized version of BricsCAD, use the localized command name, or enter the English command name it with an underscore prefix as _-RENAME. If you use an old version of BricsCAD, then lisp may be the only option.
0 -
You might give this a try:
http://www.theswamp.org/index.php?topic=50351.msg554803#msg5548030 -
Here is another :
http://www.theswamp.org/index.php?topic=32766.msg382466#msg3824660