block rename lsp

block rename lsp

nychoe1
Advocate Advocate
1,562 Views
3 Replies
Message 1 of 4

block rename lsp

nychoe1
Advocate
Advocate

hello,  I have a lsp that changing block name

this lsp changed  Anonymous name but do not change block name. why?
attached image file
I want to change block name. not Anonymous name
(defun c:bb (/)
   (setq ss (entsel "\nselect"))
   (setq ent (car ss))
   (setq ent_list (entget ent))
   (setq blk_name (cdr (assoc 2 ent_list)))
   (setq acad_obj  (vlax-get-acad-object)
         doc (vla-get-ActiveDocument acad_obj)
         blocks    (vla-get-blocks doc)
         blk_old   (vla-item blocks blk_name)
   )
   (setq new_name (getstring (strcat "\ncurrent <" blk_name "> new name ")))
   (vla-put-name blk_old new_name)
   (princ)
);defun
0 Likes
Accepted solutions (1)
1,563 Views
3 Replies
Replies (3)
Message 2 of 4

dbhunia
Advisor
Advisor

Try this...

 


@nychoe1 wrote:

hello,  I have a lsp that changing block name

this lsp changed  Anonymous name but do not change block name. why?
attached image file
I want to change block name. not Anonymous name
(defun c:bb (/)
   (setq ss (entsel "\nselect"))
   (setq ent (car ss))
   (setq ent_list (entget ent))
   (setq blk_name (cdr (assoc 2 ent_list)))
   (setq acad_obj  (vlax-get-acad-object)
         doc (vla-get-ActiveDocument acad_obj)
         blocks    (vla-get-Blocks doc)
         blk_old   (vla-item blocks blk_name)
   )
   (setq new_name (getstring (strcat "\ncurrent <" blk_name "> new name ")))
   (vla-put-name blk_old new_name)
   (princ)
);defun

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 4

cadffm
Consultant
Consultant
Accepted solution

@dbhunia 

Function names are not case-sensitive

 

@nychoe1 

Why should?

Why should  the real blockname change (called "anonymous Name" in LIST command output, but it is the real name and the other one is the fake name = EFFECTIVENAME).

 

You selected and changed the Block "BlockA", no other blocks, just this one, you didn't rename Block "*U24", or?

 

Rule1: A Block is just one time in the document, all block-references of this block displays this one block content,

so all blockreferences looks the same (except few thing ~ rotation, scaling, byblock , Layer0..)

 

Rule1 was correct 20 years ago, Rule1 is correct still today, so how are dynamic blocks possible? Aren't possible, it's just a fake.

 

Crash course dynamic Block concept overview:

Block-defintion BlkA (dynamik block, say a stretchable rectangle).

Create a new block-reference, it is 100% the same like a non-dynamic block, block-reference refer to block BlkA.

Now, you change the dynamic parameter (stretch the rectangle)...

In the background autocad creates a new block with ab block name "*Unnn",

the edited block-reference refer to block "Unnn" now, and not longer to Block BlkA.

 

But AutoCAD knowing that "*Unnn" is a variant of "BlkA" (on good days)

and you can get the "template blockname" by EFFECTIVENAME property.

 

Change you Lisp from

   (setq ent_list (entget ent))
   (setq blk_name (cdr (assoc 2 ent_list)))

to

   (setq blk_name (vla-get-effectivename (vlax-ename->vla-object ent)))

 

 

Sebastian

Message 4 of 4

nychoe1
Advocate
Advocate

thank you...

0 Likes