Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

Thanks David, but his suggestion does not change "blk_oldname" if "blk_newname" already exists in the drawing.

Posted

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

Posted

David,

I need a routine to rename the block "bkl_nameX" to "blk_nameY" even though "blk_nameY" is already present in the drawing.

Posted

Then you will have to overwrite the black table definition of blk_nameY. You cannot just rename it. -David

Posted

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.

Posted

I want to rename B14x19 to BE14x19x19.

 

Is the geometry exactly the same in both blocks? -David

Posted

Yes is the same block. I have drawings with equal blocks with different names.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...