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.
@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: ")))
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."
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."
@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.
@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.]
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."