guitarguy1685 Posted October 4, 2017 Posted October 4, 2017 first off I know a rename block lisp already exists in many forms, I just wanted to try one out myself. 1st Question, what's the difference between Name and EffectiveName of a block? I thought this lisp would work but i'm getting an error (defun c:test () (setq Block (entsel) BlockOBject (vlax-ename->vla-object (car Block)) BlockName (vlax-get-property BlockObject 'Name) newname (getstring "\nEnter new name: ") ) (vlax-put-property BlockObject 'Name newname) (princ) ) this gives me this error ; error: Automation Error. Key not found what am I missing? Quote
Roy_043 Posted October 4, 2017 Posted October 4, 2017 There is no block definition named newname. Quote
rlx Posted October 4, 2017 Posted October 4, 2017 Effective blockname property is available for dynamic blocks. When you want to modify a property for an object its best / safest to first check if property is available. Just a few random lines from one of my appies : (defun RlxBlk_SelectOldBlockNameOnScreen ( / ss bob vis) (princ "\nSelect Block or space/enter for main dialog: ") (if (and (setq ss (ssget ":s" '((0 . "INSERT")))) (setq bob (vlax-ename->vla-object (ssname ss 0))) (vlax-property-available-p bob 'effectivename)) (progn (setq #RlxBlk-OldBlockName (vla-get-effectivename bob)) (if (setq vis (GetBVis bob))(setq #RlxBlk-OldVisibilityName vis)) (set_tile "eb_old_blk_name" #RlxBlk-OldBlockName))) (RlxBlk_ShowMainDialog)) If you modify a block (block definition) all blocks will be updated. To prevent this for dynamic blocks each block is given a sort of temp. name beginning with *U. see also http://www.lee-mac.com/dynamicblockfunctions.html gr. Rlx Quote
Grrr Posted October 4, 2017 Posted October 4, 2017 (edited) EffectiveName property is read-only. Also you have to change the 'Name property of the block definition and not the block reference as you were trying: (and (setq (car (entsel "\nSelect block to rename: "))) (= "AcDbBlockReference" (vla-get-ObjectName (setq ref (vlax-ename->vla-object ref)))) (/= "" (setq newname (getstring T "\nEnter new name: "))) (snvalid newname) (not (tblsearch "BLOCK" newname)) (setq def (vla-item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-get-EffectiveName ref))) (vl-catch-all-apply 'vlax-put-property (list def 'Name newname)) ) Edited October 4, 2017 by Grrr code corrected Quote
ronjonp Posted October 4, 2017 Posted October 4, 2017 (edited) Here's another way to rename the block record without activex: (defun c:foo (/ en) (while (and (setq e (car (entsel "\nPick a block to change its name: "))) (= "INSERT" (cdr (assoc 0 (entget e)))) (setq e (cdr (assoc 330 (entget (tblobjname "block" (cdr (assoc 2 (entget e)))))))) (setq n (getstring "\nEnter new name: ")) ) (if (tblobjname "block" n) (alert (strcat "Block name " n " is already in use...")) (entmod (subst (cons 2 n) (assoc 2 (entget e)) (entget e))) ) ) (princ) ) Edited October 5, 2017 by ronjonp Quote
Tharwat Posted October 4, 2017 Posted October 4, 2017 Hi Grrr, Your and function will error if the user picked nothing and will not pass over that. Quote
Grrr Posted October 4, 2017 Posted October 4, 2017 Hi Tharwat, I know, just wanted to provide simple example without much error-checking - example corrected a bit. Quote
guitarguy1685 Posted October 4, 2017 Author Posted October 4, 2017 Thanks for the info about EffectiveName. That's good to know, i'll need this later. I still don't understand why (vlax-put-property BlockObject 'Name "test name") retuns ; error: Automation Error. Key not found If I write (vlax-put-property BlockObject 'Rotation 45) This works. What am I missing? Quote
rlx Posted October 4, 2017 Posted October 4, 2017 (edited) Thanks for the info about EffectiveName. That's good to know, i'll need this later. I still don't understand why (vlax-put-property BlockObject 'Name "test name") retuns If I write (vlax-put-property BlockObject 'Rotation 45) This works. What am I missing? You're missing the point of post #4 (hint : read-only property). You can't change the name of a block that way ... gr. Rlx you can only change the name of the block definition If you like digital SM look at : http://www.cadtutor.net/forum/showthread.php?100670-RlxBlk-Replace-Redefine-blocks-visibility-states-preview-and-link-attributes&highlight=rlxblk in this lisp file I rename a block (definition) as follows : (defun rename_block_definition ( $bn / bn ) (if (and (not (void $bn)) (tblsearch "block" $bn)) (vla-put-name (Collection-Member $bn (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)))) (setq bn (create_unique_blockname $bn)))) bn) Edited October 4, 2017 by rlx Quote
Roy_043 Posted October 5, 2017 Posted October 5, 2017 @rlx: What you are saying is not correct. The name property of a block reference is not read-only. But if you want to change it a block definition with the new name must already exist. Quote
rlx Posted October 5, 2017 Posted October 5, 2017 @rlx:What you are saying is not correct. The name property of a block reference is not read-only. But if you want to change it a block definition with the new name must already exist. you're right Roy , should have said effectivename Quote
Grrr Posted October 5, 2017 Posted October 5, 2017 Ok, to clear-up things here: first off I know a rename block lisp already exists in many forms I thought that the OP wanted to rename a block (block definition) and not that he wanted to substitute a block reference with another. Heres the vanilla approach, I'm more familiar with: _$ (setq enx (entget (car (entsel)))) ((-1 . <Entity name: b9ca204f00>) (0 . "INSERT") (330 . <Entity name: b9ca2089f0>) (5 . "288") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbBlockReference") (2 . "Squares") (10 1619.5 -113.484 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) _$ (entmod (subst (cons 2 "NewBlock") (assoc 2 enx) enx)) ((-1 . <Entity name: b9ca204f00>) (0 . "INSERT") (330 . <Entity name: b9ca2089f0>) (5 . "288") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbBlockReference") (2 . "NewBlock") (10 1619.5 -113.484 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) And here I did some investigation with activex, since I never used the 'Name property: ; (vlax-property-available-p obj prop [check-modify]) (setq o (vlax-ename->vla-object (car (entsel "\nSelect a block: ")))) _$ (vlax-property-available-p o 'Name) ; available T _$ (vlax-property-available-p o 'EffectiveName) ; available T _$ (vlax-property-available-p o 'Name T) ; not read-only T _$ (vlax-property-available-p o 'EffectiveName T) ; is read-only nil ; "UnExistingBlock" definition does not exist in the drawing: _$ (vlax-put-property o 'Name "UnExistingBlock") Error: Automation Error. Key not found ; "NewBlock" definition exist in the drawing: _$ (vlax-put-property o 'EffectiveName "NewBlock") Error: ActiveX Server returned an error: Type mismatch ; Works: _$ (vlax-put-property o 'Name "NewBlock") ; and is not case-sensitive nil I never used this kind of block reference substitution, since what happens when you deal with attributed blocks ? IMO more safely is to reinsert the block and match the properties of the previous one. 1st Question, what's the difference between Name and EffectiveName of a block? Thats partially answered by rlx : Effective blockname property is available for dynamic blocks. But as I understand the "Name" property returns the annonymous name, while "EffectiveName" returns the true block name. So the 'Name property is the same as the group code 2. Guess you'll ask "whats annonymous name ?" - Try creating a dynamic block, then change one of its parameters and then check its 'Name and 'EffectiveName properties. The 'Name property should wcmatch to "`**" (since to match the new block geometry - an annonymous block definition and reference were generated), while the EffectiveName would keep the original/source block name. I thought this lisp would work but i'm getting an error ... this gives me this error ; error: Automation Error. Key not found what am I missing? Replicating your error: ; "UnExistingBlock" definition does not exist in the drawing: _$ (vlax-put-property o 'Name "UnExistingBlock") Error: Automation Error. Key not found Quote
rlx Posted October 5, 2017 Posted October 5, 2017 (edited) Putting a new name on a existing block , either subst group code 2 or using vl-, can have the undesirable effect of having 2 of the same blocks but with different attributes and that's basically the reason I made my RlxBlk appie which allows me to choose to replace the selected blocks or to completely redefine them and at the same time be able to (re)link attributes from one block to another. But I agree with Grrr that at this time it is unclear what OP's intensions are. Gr. Rlx Edited October 5, 2017 by rlx Quote
guitarguy1685 Posted October 5, 2017 Author Posted October 5, 2017 (edited) You're missing the point of post #4 (hint : read-only property). You can't change the name of a block that way ... Sorry, I thought it was EffectiveName that was read-only not both. Edited October 5, 2017 by guitarguy1685 new info Quote
rlx Posted October 5, 2017 Posted October 5, 2017 Sorry, I thought it was EffectiveName that was read-only not both. that's correct and I was punished for it :-) gr.Rlx Quote
guitarguy1685 Posted October 5, 2017 Author Posted October 5, 2017 oh god, i'm an idiot. I see what you guys are talking about. I was trying to change the name of that one individual block not "Block Definition" that defines all blocks of that type. my bad Quote
rlx Posted October 5, 2017 Posted October 5, 2017 (edited) let him (or her) who never makes mistakes cast the first stone ps. although my blk appie does the job , is't , well a dragon, so maybe this is what you're after? http://www.lee-mac.com/copyblock.html gr. Rlx Edited October 5, 2017 by rlx Quote
guitarguy1685 Posted October 5, 2017 Author Posted October 5, 2017 yes, lee-macs block lisps are awesome. I use that one quite a bit. Although the Rename Block command doesn't do what I expected it to do. Forexample, when I make a flat shot the block name is something like "$%!@#!@#ASDFASDD!@#" I thought I would be able to use RENAMEBLOCK to rename the block. What it does is create a new block with the new name. The original block still remains in the drawing. However this command is still very useful anyways. I just want to rename a block to something that makes sense. Also I've seen may LISPS that do this using DXF codes. I just thought I could do it with vlisp. This is the lisp I found that i'm using, written back in '98 (defun C:RBLOCK (/ SB SBD OLD_NAME NEW_NAME) (setq SB NIL) (while (null SB) (setq SB (entsel "\nSelect block to RENAME: ")) (if SB (progn (setq SB (car SB) SBD (entget SB)) (if (= (cdr (assoc 0 SBD)) "INSERT") (redraw SB) (progn (redraw SB) (setq SB NIL) (princ "\nItem selected is not a block.") ) ) ) (princ "\nNothing selected. Try again.") );end if ) (setq OLD_NAME (cdr (assoc 2 SBD))) (princ (strcat "\n OLD Block Name: " OLD_NAME)) (setq NEW_NAME (getstring "\n NEW Block Name: ")) (command "rename" "b" OLD_NAME NEW_NAME) (princ (strcat "\n BLOCK RENAMED TO: " NEW_NAME)) (princ) ) Quote
ronjonp Posted October 5, 2017 Posted October 5, 2017 THIS code should accomplish the same thing. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.