Lisp for auto labelling the CAD block

Lisp for auto labelling the CAD block

aaditya.desai
Participant Participant
1,378 Views
18 Replies
Message 1 of 19

Lisp for auto labelling the CAD block

aaditya.desai
Participant
Participant

I want a lisp program which will help me label my blocks as per their description written in property box. All I need is when I select the block it should automatically pick its description so that I can save a lot of time and don't have to manually write the description.

0 Likes
1,379 Views
18 Replies
Replies (18)
Message 2 of 19

ВeekeeCZ
Consultant
Consultant

Regular blocks have no description property. So, what are you talking about? Post a sample.

0 Likes
Message 3 of 19

aaditya.desai
Participant
Participant

I have various labels. I want the "NAME_LOCAL" description to be displayed.

0 Likes
Message 4 of 19

Kent1Cooper
Consultant
Consultant

@aaditya.desai wrote:

I have various labels. I want the "NAME_LOCAL" description to be displayed.


Won't it be displayed as a matter of course unless you have that Attribute defined to be Invisible?  If it is, you can change that in REFEDIT or BEDIT [select it and change the Invisible option in the Properties palette to "No"], and follow with ATTSYNC to make it appear.

Kent Cooper, AIA
0 Likes
Message 5 of 19

ВeekeeCZ
Consultant
Consultant

Ok, understand. It sounds great to have such a routine.

Message 6 of 19

aaditya.desai
Participant
Participant

Can you explain this in a simple manner? Which steps do I need to take? I am new to this.

0 Likes
Message 7 of 19

aaditya.desai
Participant
Participant

Now that it is conveyed, do you have any solution to this? I have more than 200 blocks in the template file we have with the same attributes in each block. So, when I select the block, it should show me "NAME_LOCAL" directly.

0 Likes
Message 8 of 19

Kent1Cooper
Consultant
Consultant

@aaditya.desai wrote:

.... when I select the block, it should show me "NAME_LOCAL" directly.


If you just want to see it reported at the Command line, and not necessarily have it become visible in the drawing, for testing paste this in at the Command line:

(getpropertyvalue (car (entsel "\nSelect Block: ")) "NAME_LOCAL")

 

[followed by Enter to register it] and pick a Block.

 

If that gives you what you want, it can be defined into a command name that you can type in or set into a Tool Palette button, or....  It could report it in an (alert) box up in the screen if you prefer, or write it as Text into the drawing, or....

Kent Cooper, AIA
0 Likes
Message 9 of 19

aaditya.desai
Participant
Participant

Hello,

 

See the image below for reference on what I want to do.

aadityadesai_1-1729777527916.png

 

When I give leader note to a block. It should pick the description from the Attribute section "NAME_LOCAL" and it should directly show the note. I typed this manually. This might help you with my query.

0 Likes
Message 10 of 19

Kent1Cooper
Consultant
Consultant

@aaditya.desai wrote:

Can you explain this in a simple manner? Which steps do I need to take? I am new to this.


Enter the command name REFEDIT and pick an insertion of the Block, and confirm that's the Block name you want to Edit.  Type PROPERTIES if you don't already have the Properties palette showing.  Select the Attribute-Definition object.  In Properties, there's a Misc category of entries at the bottom, one of which is Invisible.  Set that to NoREFCLOSE, Save, check OK.  ATTSYNC, give it the Block name or choose the <Select> option and pick one, Yes.

 

The procedure would be very similar with the BEDIT command rather than REFEDIT.  You can try both and see which you prefer.  Read about them in Help [always the first step].

Kent Cooper, AIA
0 Likes
Message 11 of 19

Kent1Cooper
Consultant
Consultant

@aaditya.desai wrote:

.... When I give leader note to a block. It should pick the description from the Attribute section "NAME_LOCAL" and it should directly show the note. ....


That's certainly possible, but:  Using the point at which you picked the Block for the tip of the arrow, or some location calculated relative to the Block?  Always just using the current Layer and Dimension Style for the Leader and Text Style and size for the Text, or should those be built into the routine?  Automatic Leader route and number of points and Text positioning, or up to the User?  Mleader instead of Leader, perhaps?  Etc.

Kent Cooper, AIA
0 Likes
Message 12 of 19

aaditya.desai
Participant
Participant

The location of the leader point does not concern me as long as it is located at the block. I just need to show the names of the blocks as I prepare the details. The layer is already set for dimensions and leaders, so if it doesn't put the leader in the respective layer, I will manually put it in its respective layer. 

0 Likes
Message 13 of 19

Kent1Cooper
Consultant
Consultant

If you're willing to be limited to a two-point Leader only, in extremely simplest terms, this seems to work:

 

(defun C:BNALT (/ sel blk) ; = Block Name-Attribute Leader Tag
  (if
    (and
      (setq sel (entsel "\nSelect Block to label with its NAME_LOCAL Attribute: "))
      (member '(0 . "INSERT") (entget (setq blk (car sel))))
    ); and
    (command "_.leader" "_non" (cadr sel) pause "" (getpropertyvalue blk "NAME_LOCAL") "")
  ); if
  (prin1)
)

 

It will throw an error if the selected Block does not have an Attribute with that Tag -- there's probably some way to account for that.  It will just do nothing if you select something other than a Block [part of the "extremely simplest terms"], but could be made to scold you instead, and/or ask you again to select.

 

[EDIT:  Added the None Osnap call for the start of the Leader.]

Kent Cooper, AIA
0 Likes
Message 14 of 19

aaditya.desai
Participant
Participant

I tried this, but I have to write some text. I just want to put the leader at a specified location. For example, I select the block by typing BNALT command and it said I need to write. I just need it to automatically pick the description. Can you please help?

0 Likes
Message 15 of 19

Kent1Cooper
Consultant
Consultant

@aaditya.desai wrote:

.... I select the block by typing BNALT command and it said I need to write. ....


It works for me.  In white are the parts of the Block [Circle and NAME_LOCAL tagged Attribute Definition], in green is an insertion of the Block with a value for that Attribute [set to be visible here, but it still works if it's invisible], and in yellow the result of the BNALT command, using that Attribute's value for the Text, which did not ask for anything except to pick the Block and to place the second point of the Leader.

Kent1Cooper_0-1729861005127.png

Run it again and show us the Command-line history of prompts.  For me it looks like just this:

Command: BNALT

Select Block to label with its NAME_LOCAL Attribute: {I picked it}  _.leader
Specify leader start point:  {it supplied this}
Specify next point:  {I picked a location}
Specify next point or [Annotation/Format/Undo] <Annotation>:  {it supplied Enter for the default}
Enter first line of annotation text or <options>: Test Name Enter next line of annotation text: {it supplied the content and concluding Enter}
Command:

Kent Cooper, AIA
0 Likes
Message 16 of 19

ec-cad
Collaborator
Collaborator

Kent,

I'm thinking maybe the OP was confused by the Prompt

"Select Block to label with its NAME_LOCAL Attribute: "

And thought it wanted the Attribute Value to be typed in ?

Your routine works good for a 2-point Leader, and picking a block

with the Attribute Tagname "NAME_LOCAL".

 

ECCAD

 

0 Likes
Message 17 of 19

aaditya.desai
Participant
Participant

I think you got it. I want the value of the attribute automatically typed in. I just want to place the leader.

0 Likes
Message 18 of 19

Kent1Cooper
Consultant
Consultant

@aaditya.desai wrote:

.... I want the value of the attribute automatically typed in. I just want to place the leader.


And that's the way it works for me.  Does it not for you?  If not, tell us what happens instead, in detail.

Kent Cooper, AIA
0 Likes
Message 19 of 19

ec-cad
Collaborator
Collaborator

Kent1Cooper's Lisp (does) work just fine.

Just do an Appload, and load it or drag / drop the .lsp into Acad.

 

I'll describe what it does.

First, at Command Prompt - type in BNALT<Enter>

   --- (don't pick the Block, then type BNALT)

When prompted, select your Block.

The Lisp will use the Point you picked to start the Leader.

It then will pause for you to pick a 2nd point for the Leader (direction).

You pick that 2nd point, and a Leader will be placed with the Arrow at

the 1st point, and the leader vectors to the 2nd point.

It then gets the 'value' of the Attribute Tag "NAME_LOCAL", and puts

that value as Annotation for the Leader.

 

IF (nothing) happens, the Block picked does not have an Attribute "NAME_LOCAL".

IF picking those (2) points does not result in a Leader, that's a different issue.

IF you get a Leader, with (no) Annotation, it may be caused by a couple of

conditions. 1, there was no Value found in the Attribute - (was "")

or                 2, your textsize is way to small.

 

Hope that helps you.

 

ECCAD

0 Likes