antistar Posted August 15, 2010 Posted August 15, 2010 Hi to all, I use this routine that renames blocks. It works well, but how do I change it to also rename when "blk_newname" is already in the drawing? ;-------------------------------------------------------- (defun renblock (ob nb / ss i ent ) (cond ((and (tblsearch "block" ob) (not (tblsearch "block" nb))) (command "._rename" "block" ob nb) ) ((and (tblsearch "block" ob)(tblsearch "block" nb)) (setq ss (ssget "x" (list (cons 2 ob)))) (setq i -1) (repeat (sslength ss) (setq ent (entget (ssname ss (setq i (1+ i)))) ent (subst (cons 2 nl) (cons 2 (cdr (assoc 2 ent))) ent) ) (entmod ent) ) ) ((not (tblsearch "block" ob)) (prompt (strcat "\nBlock " ob " not found. ")) ) ) (princ) ) ;rename blocks (defun c:RB () (renblock "blk_oldname" "blk_newname") ) ;--------------------------------------------------------- Thanks in advance Quote
Tharwat Posted August 15, 2010 Posted August 15, 2010 You can check the following link ; http://www.cadtutor.net/forum/showthread.php?40758-Rename-multiple-blocks&highlight=rename+multiple+blocks Regards, Tharwat Quote
David Bethel Posted August 15, 2010 Posted August 15, 2010 I think, that the basic logic was OK. Try changing variable nl to nb. Hi to all, I use this routine that renames blocks. It works well, but how do I change it to also rename when "blk_newname" is already in the drawing? [color=blue];--------------------------------------------------------[/color] [color=blue](defun renblock (ob nb / ss i ent )[/color] [size=2][color=blue](cond ((and (tblsearch "block" ob) (not (tblsearch "block" nb))) [/color][/size] [size=2][color=blue](command "._rename" "block" ob nb)[/color][/size] [size=2][color=blue])[/color][/size] [size=2][color=blue]((and (tblsearch "block" ob)(tblsearch "block" nb))[/color][/size] [size=2][color=blue](setq ss (ssget "x" (list (cons 2 ob))))[/color][/size] [size=2][color=blue](setq i -1)[/color][/size] [size=2][color=blue](repeat (sslength ss)[/color][/size] [size=2][color=blue](setq ent (entget (ssname ss (setq i (1+ i))))[/color][/size] [size=2][color=blue]ent (subst (cons 2 [/color][color=RED]nb[/color][color=BLUE]) (cons 2 (cdr (assoc 2 ent))) ent)[/color][/size] [size=2][color=blue]) [/color][/size] [size=2][color=blue](entmod ent)[/color][/size] [size=2][color=blue])[/color][/size] [size=2][color=blue])[/color][/size] [size=2][color=blue]((not (tblsearch "block" ob))[/color][/size] [size=2][color=blue](prompt (strcat "\nBlock " ob " not found. "))[/color][/size] [size=2][color=blue])[/color][/size] [size=2][color=blue])[/color][/size] [size=2][color=blue](princ)[/color][/size] [size=2][color=blue])[/color][/size] [size=2][color=blue];rename blocks[/color][/size] [size=2][color=blue](defun c:RB ()[/color][/size] [size=2][color=blue](renblock "blk_oldname" "blk_newname")[/color][/size] [size=2][color=blue])[/color][/size] [size=2][color=#0000ff];---------------------------------------------------------[/color][/size] [size=2][color=black]Thanks in advance[/color][/size] Maybe just a typo. -David Quote
antistar Posted August 15, 2010 Author Posted August 15, 2010 Thanks David, but his suggestion does not change "blk_oldname" if "blk_newname" already exists in the drawing. Quote
David Bethel Posted August 15, 2010 Posted August 15, 2010 It doesn't change the block name, but it should be changing the name of all existing INSERTs of blk_oldname to blk_newname. If blk_oldname is nested anywhere, you would then have to step through the entire BLOCK table and update all of the nested INSERTs there as well. Then you should be able to purge blk_oldname. But then the question is which BLOCK definition do you wish to use oldname or newname? -David Quote
antistar Posted August 15, 2010 Author Posted August 15, 2010 David, I need a routine to rename the block "bkl_nameX" to "blk_nameY" even though "blk_nameY" is already present in the drawing. Quote
David Bethel Posted August 15, 2010 Posted August 15, 2010 Then you will have to overwrite the black table definition of blk_nameY. You cannot just rename it. -David Quote
antistar Posted August 15, 2010 Author Posted August 15, 2010 I have the following blocks in the design: B14x19; BE14x19x19 ... I want to rename B14x19 to BE14x19x19. I thought there was a way to rename multiple blocks with AutoLISP. Even with blocks already in the drawing. Thank you for your attention and patience. Have a nice day. Quote
David Bethel Posted August 15, 2010 Posted August 15, 2010 I want to rename B14x19 to BE14x19x19. Is the geometry exactly the same in both blocks? -David Quote
antistar Posted August 15, 2010 Author Posted August 15, 2010 Yes is the same block. I have drawings with equal blocks with different names. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.