Message 1 of 37
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is there lisp routine that will allow you to rename multiple blocks at once?
Thanks,
Anderson51
Solved! Go to Solution.
Is there lisp routine that will allow you to rename multiple blocks at once?
Thanks,
Anderson51
Solved! Go to Solution.
There sure is:
(defun c:RMB ( / lstBlocks) ;Rename Multiple Blocks ;Prep (setq lstBlocks '( ;("old_name" "new_name") ("Block A" "Block 1") ("BLOCK B" "Block 2") )) ;Begin work (setvar 'CMDECHO 0) (foreach blk lstBlocks (command "-RENAME" "b" (car blk) (cadr blk)) );foreach (setvar 'CMDECHO 1) ;Finish up (prompt "\nBlock Re-Naming Complete.") (princ) );defun
You may find these code snippets useful https://jtbworld.com/autocad-axblock-lsp and if you find you need further help feel free to use the contact page. JTB Batch Change is another option.
Is there a way to have it pull up in list form, similar to how the rename command works?
Yes it can be done. Either learn to program, hope someone create it for free or pay to get it done. I can help but not for free.
Have a nice day Jimmy!
I don't understand. If you want to rename them via a form, then why not just use the original RENAME command?
I can not think of any effective mechanic / workflow to rename multiple blocks at once via a form that would be more-efficient than the original command..
Can you describe what you have in mind that would be faster?
Because, we can easily create a form to select multiple blocks at once.. but then what.. loop through each one asking for a new name? that would be essentially the same as the original command.
Best,
~DD
(defun c:renmblocks nil (renmblocks))
(defun renmblocks ( / get-blocks getallblocks nonincluded blocklist dont oldblock newname)
(defun getblocks (/ adoc name lst)
(vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(if (and (equal (vla-get-IsLayout block) :vlax-false)
(equal (vla-get-IsXref block) :vlax-false)
(/= (substr (vla-get-Name block) 1 1) "*"))
(setq lst (cons (vla-get-Name block) lst))
)
)
lst
)
(defun getallblocks ( / lst)(vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))(setq lst (cons (vla-get-Name block) lst))) lst)
(defun nonincluded(a b) (if a (if (not(member (car a) b)) (cons (car a) (nonincluded (cdr a) b)) (nonincluded (cdr a)b) ) ) )
(setq blocklist (getblocks))
(setq dont (nonincluded (getallblocks) blocklist))
(foreach bname blocklist
(initget 1)
(setq newname (getstring (strcat"\nNew name for block <" bname ">:" )))
(setq oldblock (vla-item(vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) bname))
(if
(and
(> (strlen newname) 0)
(not (member newname dont))
)
(vlax-put oldblock 'name newname)
)
)
(princ "\nDone")
)
(princ)
Miljenko Hatlak
@JTBWorld wrote:
You may find these code snippets useful https://jtbworld.com/autocad-axblock-lsp
;;; By Jimmy Bergmark
;;; Copyright (C) 1997-2016 JTB World Inc., All Rights Reserved
Thats is a classic 😊
@hak_vz ,
If OP is NOT trying to rename EVERY block, then I do not think that looping through every block in the drawing and asking for each to be renamed is a practical or efficient method. Again, I believe the original command would accomplish it better.
--EDIT--
Also, I do not believe that the (initget 1) flag works on the (getstring ...) method.
Best,
~DD
The fact that you have to invoke the command each time slows you down. Also, you have to scroll thru the list each time to find the block you want to rename, depending on the list size, you could be scrolling a while to find the block.
It would definitely save time to pick multiple and rename multiple at the same time.
Thanks,
Anderson51
@CodeDing wrote:@hak_vz ,
If OP is NOT trying to rename EVERY block, then I do not think that looping through every block in the drawing and asking for each to be renamed is a practical or efficient method. Again, I believe the original command would accomplish it better.
DD I agree with you. Original command is best option, at least from security point of view,
It actually mimics -rename, but then offer names of all blocks that can be modified (removes xrefs and layouts).
To skip rename one just have to hit <enter>
I've jumbled this code in last 20 mins just for fun, so you can find some stupid entries i.e initget on getstring 🙂
Miljenko Hatlak
Just checking: Are you aware of the use of "*" as a wildcard?
@anderson51 wrote:
....
It would definitely save time to pick multiple and rename multiple at the same time.
....
I'm trying to understand the procedure you envision. Say you can pick multiple Block names that you want to rename, from a list or dialog box or something. Then what? How are you expecting to give them their new names, other than one at a time?
@anderson51 wrote:
The fact that you have to invoke the command each time slows you down....
Are you aware that you can actually hit the button "Rename To" to quickly rename an item without closing a dialog...
Below is an example list.
Say I wanted to rename the following:
DS-145-301-a1 to DS-146-302-a8
DS-145-301-a2 to DS-146-302-a9
DS-145-301-a3 to DS-146-302-a10
I would have to invoke the command 3 separate times, scroll to the block, and rename accordingly. It would be nice to take care of it all during the single execution of the command.
The existing rename command would work perfectly if you could simply "OK" it without it exiting the command, and moving on to the next block you want to rename....if that makes sense?
WOW.
I was completely unaware that you could simply click "rename to" and move on to the next one. For some reason I was under the impression you had to click OK in order to complete the renaming.
Learn something new everyday.
Thanks
In addition to using that handy "Rename to" button, you could also take advantage of using the "*" wildcard character to expedite some of the renaming. It may be necessary to do the renaming in stages, e.g. first change "145-301" to "146-302", followed by the other segments.
I am not sure I am following what you mean, can you give me an example?
Thanks