RenamePastedBlock

RenamePastedBlock

miroko
Enthusiast Enthusiast
413 Views
2 Replies
Message 1 of 3

RenamePastedBlock

miroko
Enthusiast
Enthusiast

Hi,

 

This is propbably a simple one for author or for anyone who is good in lisp.

 

Attached is lisp which is adding command changing name of pasted already block by just selecting it.

 

It is very nice.

 

Only one thing which users do not so much may like is that it works such that you need to select the block after function is started.

I mean if user just select a block and start command he still need to select this block again.

 

Is it possible to adjust that lisp so that it will work in both cases: selecting before command is started and selecting after command is started ?

 

A nice addition would be also a window which appear on screen where one need to enter name, it kind of make user more aware of whats happening. This is tried self by pasting some code from other post but obviously it was not that simple.

 

 

Could you help ?

 

Here is lisp.

 

;beginning

;;  RenameBlock.lsp [command name: RB]
;;  To Rename a selected Block to a User-specified new
;;    name, without needing to know its current name.
;;  Kent Cooper, last edited 18 April 2013

(defun C:RB (/ 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)
); defun

;end

 

 

regards

miroko

0 Likes
Accepted solutions (1)
414 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

@miroko wrote:

.... 

Attached is lisp which is adding command changing name of pasted already block by just selecting it.

 

It is very nice.

 

Only one thing ... you need to select the block after function is started.

.... 

Is it possible to adjust that lisp so that it will work in both cases: selecting before command is started and selecting after command is started ?

 

A nice addition would be also a window which appear on screen where one need to enter name, it kind of make user more aware of whats happening. This is tried self by pasting some code from other post but obviously it was not that simple.

....


I stole some code from another routine about using a pre-selected object if there is one [noun-verb functionality], and even narrowing the selection down to just one Block if there is one of those along with other stuff.  I also added a check on whether the new Block name is already used from the PasteBlockWithName.lsp routine.  And I added accounting for the possibility of a dynamic Block, to get its Effective Name instead of the "anonymous" name of an individual insertion.  There are a few other lesser enhancements, too [highlighting it, letting you keep the original name if you decide to, etc.].  This has the same "issue" as PasteBlockWithName, using a Text Editor that has an option for "Full Editor" [meant for Mtext and the like], but at least it warns you in a prompt not to use that.

 

[By the way, Cadalyst CAD Tips named the Tip where this is posted with the word "Pasted" in it, because the main incentive for making the original routine was to give meaningful names to Blocks brought in with PasteBlock that get wacky names from AutoCAD.  But as I commented there, both that original and this updated one work with any Block at all -- it doesn't need to be a "pasted" one.]

Kent Cooper, AIA
0 Likes
Message 3 of 3

miroko
Enthusiast
Enthusiast

hi,

 

Of course is working as it should 🙂

 

Thank you for help.

 

 

regards

miroko

0 Likes