RENAME BLOCK

Hello,
Thank you to everyone who helped guide here.
my question is: the following lisp block is changing its name. but the blocks with the same name all change. What should I do for such a change? For each block, even if there is more than one block with the same name, changing the specific name of the block, as well as not changing the others.



(defun c:rb/Rename/Block/Single (/ old new cmde); = Rename user-selected Block
(while
(not
(and
(setq bent (car (entsel "\nSelect Block to Rename: ")))
(setq bdata (entget bent))
(= (cdr (assoc 0 bdata)) "INSERT")
(setq old (cdr (assoc 2 bdata)))
(not (assoc 1 (tblsearch "block" old))); not an Xref
); and
); not
(prompt "\nNothing selected, or not a Block.")
); end while
(setq new (getstring T (strcat "\nCurrent name = " old ". New Block Name: ")))
(if (/= new ""); User entered a new name
(progn ; then
(setq cmde (getvar 'cmdecho))
(setvar 'cmdecho 0)
(command "_.rename" "_block" old new)
(setvar 'cmdecho cmde)
); progn
); if
(princ ))

Comments

  • Yes, a block, by definition, is a set of objects that are defined by a name. Each instance of the block is saved only as the reference, with information like its insertion point. Edit the block objects, or the name of a block, and all instances show the same change.

    I am not sure of what your end goal is. But, I think you want to create a new block, that is a copy of some existing block. Perhaps that new version will later be edited to be different in some way.

    I don't know how you would do it with programming. I often default to macros if it is at all possible. But, I am not sure how to obtain the insertion point of the block. Here may be a sequence of logical steps to follow.
    1. First select a block and obtain the insertion point of the block, which must be saved.
    2. Copy the block on top of itself.
    3. Use the EXPLODE command on the LAST object created. (Last is one option for selection)
    4. Start the command to create a block.
    5. Enter the new name.
    6. Enter the insertion point that was saved at the start.
    7. To select the objects, just use PREVIOUS, and the individual objects that resulted from the EXPLODE command will be selected.
    8. As soon as you end the selection process, the new block has been created, on whatever your current layer is.
    It may help to debug, if instead of copying the block onto the same spot, you offset it to some known distance.

    -Joe
  • Lee Mac has an excellent program to copy or rename a single block.
    CopyRenameBlockV1-5.lsp
    lee-mac.com
  • thank you, this is I want.

    Lee Mac has an excellent program to copy or rename a single block.
    CopyRenameBlockV1-5.lsp
    lee-mac.com