Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Block rename

14 REPLIES 14
Reply
Message 1 of 15
Anonymous
690 Views, 14 Replies

Block rename

Anyone know if there any method where by we can do as below:-

In a drawing, simple selected a block, then click a command so i can direct rename the block name.

Currently, i need to chech the block name first,then use "RENAME" command and rename the block.

Anyone can help?
14 REPLIES 14
Message 2 of 15
Anonymous
in reply to: Anonymous

See if this will work for you.



{code}
( defun c:Renameblock ( / oldblock )
( if ( and ( setq oldblock ( car ( entsel "Please select old block:" )))
( = "INSERT" ( cdr ( assoc 0 ( entget oldblock )))) );a
( progn
( princ ( strcat "\nBlock name is \"" ( cdr ( assoc 2 ( entget oldblock ))) "\"" )); <-- use or replace with alert
( command ".rename" "BLOCK" ( cdr ( assoc 2 ( entget oldblock ))) ( Getstring ( strcat "\nEnter new block name for \"" ( cdr ( assoc 2 ( entget oldblock ))) "\" : " )) )
);p
( )
);i
( princ ))
{code}
Message 3 of 15
Kent1Cooper
in reply to: Anonymous

I suspect something about the web interface's mis-handling of angle brackets, assuming you included them in showing a default value, has screwed up what I'm seeing. So I hope I'm interpreting correctly what you're trying to do, but the prompt for a new Block name, as it came across, doesn't look right.

I would suggest adding (initget 1) prior to the (command) function, to prevent the User from hitting Enter in response to the (getstring) prompt. That's not going to be accepted as a new Block name, so you would need to handle accepting the current name, as the default, somehow.

Or, since you've notified them already what the current Block name is, maybe you don't need to include it as a default in the prompt for a new name -- you could even eliminate the (getstring) altogether, and let Rename's own prompt handle it, with a simple pause for User input:

{code}
(command
"_.rename"
"_block"
(cdr (assoc 2 (entget oldblock)))
pause
); end command
{code}

That will also deal with Enter as a response, telling them it's invalid and asking them again.

--
Kent Cooper


balisteor wrote [as it showed up on the website]...
....
( Getstring ( strcat "\nEnter new block name for \"" ( cdr ( assoc 2 ( entget oldblock ))) "\" : " ))
....
Kent Cooper, AIA
Message 4 of 15
Anonymous
in reply to: Anonymous

No i don't think there was an interface problem. I'm not as good as you Kent. 😛
Thanks for pointing that out.

I get lazy sometimes when I'm trying to answer the question to quickly too! ( should be at work )
Your solution is a better option.


{code}
( defun c:Renameblock ( / oldblock )
( if ( and ( setq oldblock ( car ( entsel "Please select old block:" )))
( = "INSERT" ( cdr ( assoc 0 ( entget oldblock )))) );a
( progn
( princ ( strcat "\nBlock name is \"" ( cdr ( assoc 2 ( entget oldblock ))) "\"" )); <-- use or replace with alert
(command
"_.rename"
"_block"
(cdr (assoc 2 (entget oldblock)))
pause
); end command
);p
( )
);i
( princ ))
{code}
Message 5 of 15
Anonymous
in reply to: Anonymous

Can i know which LISP is ok..actually i am not so understand with the LISP which you guys mention about..Is it all LISP mention in the thread is workable?
Message 6 of 15
Kent1Cooper
in reply to: Anonymous

Probably balisteor's latest code suggestion is the best one. Do you need to know how to put it into a Lisp file, and load and use it?

--
Kent Cooper
Kent Cooper, AIA
Message 7 of 15
RocksterB
in reply to: Anonymous

Thank you, I needed that!

Message 8 of 15
Kent1Cooper
in reply to: RocksterB


@Anonymous wrote:

Thank you, I needed that!


Since then, I worked up a more sophisticated version, which you can get here.  [Despite the word "pasted" in their heading, it will work on any Block.]

Kent Cooper, AIA
Message 9 of 15
RocksterB
in reply to: Kent1Cooper

Thanks for the update! One thing though, the newer routine has a problem excepting "spaces" in the rename. For example, I want to rename the block "MEC574" to "CONNECTION_TEE OUTLET TURNED UP". When I type "CONNECTION_TEE<space>, AutoCAD implies the <space> as a <Return> and invalidates the name.

 

Command:
RB
Select Block to Rename:
Current name = MEC574.  New Block Name: CONNECTION_TEE _.rename Enter object
type to rename
[Block/Dimstyle/LAyer/LType/Material/multileadeRstyle/Style/Tablestyle/Ucs/VIew/
VPort]: _block
Enter old block name: MEC574
Enter new block name: CONNECTION_TEE
A block named "CONNECTION_TEE" already exists.
*Invalid*

 

This issue did not occur in the original code posted in this thread. All in all though, I appreciate the assistance and the help! Let us know if ever you get around to updating the routine.

Message 10 of 15
Kent1Cooper
in reply to: RocksterB


@Anonymous wrote:

.... One thing though, the newer routine has a problem excepting "spaces" in the rename. ....


[Sorry this accidentally got posted without what I wanted to say....]

 

It needs the 'cr' argument in the (getstring) function to allow that [I never use spaces].  Change this line:

 

(setq new (getstring (strcat "\nCurrent name = " old ".  New Block Name: ")))

 

to this:

 

(setq new (getstring T (strcat "\nCurrent name = " old ".  New Block Name: ")))

Kent Cooper, AIA
Message 11 of 15
BlackBox_
in reply to: Anonymous

FWIW - 

 

Stemming from Beta forum discussion on the topic of 'RENAME' Command, I've developed a pseudo-named 'Right Click Rename' which contextually allows for a user to rename entity-specific aspects given the Entity Type selected.

 

Meaning, if one selects a Dimension, only those properties available to a Dimension are available via this right click menu, based upon allowed input (i.e., not on "0" or "Defpoints" layers, etc.). For disallowed Entity-specific options, that specific menu option is appropriately disabled (grayed out), yet still shown (again, for context).

 

The plug-in should be available in the Autodesk Exchange Apps store soon.



"How we think determines what we do, and what we do determines what we get."

Message 12 of 15
BlackBox_
in reply to: BlackBox_

Kent,

 

Regarding your offering over at cadalyst, the routine could be reduced to this:

 

(vl-load-com)

(defun c:RB () (c:RenameBlock))
(defun c:RenameBlock (/ eName)
  (if (and (setq eName (car (entsel "\nSelect block to rename: ")))
           (= "INSERT" (cdr (assoc 0 (entget eName))))
      )
    (command "._-rename"
             "block"
             (vla-get-effectivename
               (vlax-ename->vla-object eName)
             )
    )
    (cond (eName (prompt "\n** Must select a block ** "))
          ((prompt "\n** Nothing selected ** "))
    )
  )
  (princ)
)

 

 

... Without all of the extra, non-essential code (like error handler, setting system variable, prompting user for string, etc.), and still follow the Command's built-in operations. 

 

Also note the use of the -RENAME in lieu of RENAME Command.

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 13 of 15
RocksterB
in reply to: Kent1Cooper


@Kent1Cooper wrote:
[Sorry this accidentally got posted without what I wanted to say....]

Seem like bringing this thread back to life was a good thing!

 

That code fix took care of the <SPACE> issue. Thanks again.

Message 14 of 15
Kent1Cooper
in reply to: BlackBox_


@BlackBoxCAD wrote:

.... 

Regarding your offering over at cadalyst, the routine could be reduced to this:

.... 

... Without all of the extra, non-essential code (like error handler, setting system variable, prompting user for string, etc.), and still follow the Command's built-in operations. 

 

Also note the use of the -RENAME in lieu of RENAME Command.

....


Well, yes and no.

 

Somehow I had neglected to actually turn off CMDECHO in that routine as I intended to do [no, it's not essential, but it makes it "cleaner" in operation].  When I do that, it's usually at the beginning of a routine, often covering a variety of operations in more complex routines, in which case the error handler is there to ensure CMDECHO gets reset if [for example] the User hits Escape when being prompted.  However, I realize that in this vase, if I put the turning off of CMDECHO after all User interaction, then it won't be left turned off if they cancel the whole thing, so the error handler isn't needed after all.  The attached revised version incorporates that change [and some other little tweaks].

 

Mine allows for the User to miss or pick the wrong kind of thing, and if so, asks them to pick again; yours gives up, so the command needs to be recalled.

 

Mine notifies the User of the current name of the Block they picked [again, not essential, but...], which is another reason for it to suppress command echoing, and provide its own prompt.

 

Yours is also structured in such a way that if the User does pick a Block, the new-name prompt is issued twice.  I think that could be avoided by adding a pause for it inside the (command) function, rather than leaving it so that the command finishes after the routine is over.

 

The hyphen preceding the command name, to suppress the dialog box, is not needed inside a (command) function.  [It would be needed in a Script or Macro.]

Kent Cooper, AIA
Message 15 of 15
BlackBox_
in reply to: Kent1Cooper

You clearly do not know me (and that's fine, I am nobody important), so from the outset please know that I prefer clarity to agreement, and welcome constructive criticism.

 

 

[Kent] "Somehow I had neglected to actually turn off CMDECHO in that routine as I intended to do [no, it's not essential, but it makes it "cleaner" in operation]. When I do that, it's usually at the beginning of a routine, often covering a variety of operations in more complex routines, in which case the error handler is there to ensure CMDECHO gets reset if [for example] the User hits Escape when being prompted. However, I realize that in this vase, if I put the turning off of CMDECHO after all User interaction, then it won't be left turned off if they cancel the whole thing, so the error handler isn't needed after all. The attached revised version incorporates that change [and some other little tweaks]."

 

Respectfully, I am familiar enough with the purpose, and usage of an Error Handler within LISP, to point out that is not necessary when one codes this routine a bit more efficiently.

 

If you prefer the 'cleaner' aesthetics of blocking the Command's echo, and the inherent (also unnecessary) need to then display the Block's name for the user, so be it.

 

 

[Kent] "Mine allows for the User to miss or pick the wrong kind of thing, and if so, asks them to pick again; yours gives up, so the command needs to be recalled."

 

If you choose the While methodology, which as you've coded it requires the user to hit Escape in order to exit, that's your business... Just don't so blatantly mischaracterize.

 

The gross majority of built-in Commands operate in this manor, unlike Microstation, so casting this as some sort of design flaw is an untruth... Manual calls to RENAME suffer this same benefit (like it or not), but you already knew that.

 

Frankly, I expect more from an 'Expert Elite'.

 

 

[Kent] "Mine notifies the User of the current name of the Block they picked [again, not essential, but...], which is another reason for it to suppress command echoing, and provide its own prompt."

 

I agree that the user should have the context of knowing the original Block name, prior to entering the new Block name.

 

By nature of _not_ hiding the Command's built-in prompts, the user _is_ '[shown] the current name'... Just with less code... Again, where I choose efficiency over aesthetics.

 

Further, your code utterly neglects Dynamic Blocks, whereas my offering extract's the BlockReference Object's EffectiveName Property, which more completely allows for the renaming of both Dynamic, and non-Dynamic Blocks... Again, doing so with less code, and this time adding flexibility to a given a user's correct entity selection.

 

 

[Kent] "Yours is also structured in such a way that if the User does pick a Block, the new-name prompt is issued twice. I think that could be avoided by adding a pause for it inside the (command) function, rather than leaving it so that the command finishes after the routine is over."

 

You are correct; this is an oversight on my part (silly mistake)... I appreciate the critique.

 

 

[Kent] "The hyphen preceding the command name, to suppress the dialog box, is not needed inside a (command) function. [It would be needed in a Script or Macro.]"

 

Yet another instance of 'use what you like'; I stand by my offering, and am entirely okay with the extra, single string character given how otherwise succinct my offering is in comparison... The additional usage of Scripts doesn't directly apply to the code I posted, but would with slight modification... So thanks for pointing that out as well.

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost