Get Basic Block Name In AutoLisp - How?

Get Basic Block Name In AutoLisp - How?

brewnot
Contributor Contributor
7,317 Views
5 Replies
Message 1 of 6

Get Basic Block Name In AutoLisp - How?

brewnot
Contributor
Contributor

I want to create a simple AutoLisp routine to update a blocks, regular and dynamic. Here is the outline of steps.

 

Start command

Select block, gets [apparent block name]

-insert, [apparent block name]= (redefines block from library)

Cancel insert command

Attsync, Name, [apparent block name]

Close command

 

I hit the show stopper when selecting a block. If it is a dynamic block, the name returned is the temp name. E.g. *U143. I know there is a method to pick a block and get the base block name and not the *U143 name.

 

I have been searching the google webs and this forum, but nothing comes back that my pea sized AutoLisp knowledge bank can sort out.

 

I will be grateful for any help.

0 Likes
Accepted solutions (1)
7,318 Views
5 Replies
Replies (5)
Message 2 of 6

Ranjit_Singh
Advisor
Advisor

@brewnot wrote:

 

........ 

I hit the show stopper when selecting a block. If it is a dynamic block, the name returned is the temp name. E.g. *U143. I know there is a method to pick a block and get the base block name and not the *U143 name.

 

 


Maybe like this

(vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block: "))))
0 Likes
Message 3 of 6

brewnot
Contributor
Contributor

I have seen that, but I am missing something. what is the next step?

 

-insert XXXX=  (stop insert command)

 

What do I put in place of XXXX?

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

You could wrap that getting-the-effective-name code into a (setq) function to put it into a variable:

 

(setq bname (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block: ")))))

 

and then use that variable in appropriate places later, such as:

 

(command "_.insert" (strcat bname "=") nil)

 

EDIT:  I had the "_yes" answer in there for confirming that I wanted it redefined, but apparently it doesn't ask that from within a (command) function.

Kent Cooper, AIA
Message 5 of 6

Ranjit_Singh
Advisor
Advisor

XXX is the name of your redefined block. You have to pick that name. Something like this

(setq new_bl_name "New_test_block")
(setq input (strcat new_bl_name
                    "="
                    (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block to redefine: "))))))
0 Likes
Message 6 of 6

brewnot
Contributor
Contributor

Here is what I ended up with.

 

(defun c:blup-07 (/ bname)
(princ "\nSelect Block To Update: ")
(setq bname (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block: ")))))
(command "_.insert" (strcat bname "=") nil)
(command "_.attsync" "name" (strcat bname))
(princ)) 

 

 

Works like a charm. Has not failed me yet. Thanks to everybody for the help.

0 Likes