RENAME BLOCK
in LISP
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 ))
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 ))
0
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.- First select a block and obtain the insertion point of the block, which must be saved.
- Copy the block on top of itself.
- Use the EXPLODE command on the LAST object created. (Last is one option for selection)
- Start the command to create a block.
- Enter the new name.
- Enter the insertion point that was saved at the start.
- To select the objects, just use PREVIOUS, and the individual objects that resulted from the EXPLODE command will be selected.
- As soon as you end the selection process, the new block has been created, on whatever your current layer is.
-Joe0 - First select a block and obtain the insertion point of the block, which must be saved.
-
Lee Mac has an excellent program to copy or rename a single block.
CopyRenameBlockV1-5.lsp
lee-mac.com
0 -
thank you, this is I want.Ian Johnson said:
Lee Mac has an excellent program to copy or rename a single block.
CopyRenameBlockV1-5.lsp
lee-mac.com
0