Auto Numbering of Blocks

Auto Numbering of Blocks

MaliktheOne
Contributor Contributor
1,078 Views
9 Replies
Message 1 of 10

Auto Numbering of Blocks

MaliktheOne
Contributor
Contributor

Hello All,

 

I'm currently using AutoCAD LT 2025 and need to set up an autonumbering system for a block I've created—specifically for one side of a triangle. I'm using this block to ID my micropiles. I understand that Lisp is required for this task, but I'm not familiar with how to use it and would like if someone could help me on this. I have seen examples of auto increments of a single block but was wondering if I had control of where I want to do the increments.

 

I hope I am explaining my question and my issue correctly. 

I've attached a picture to illustrate what I'm trying to achieve. Hopefully it helps 

 

Screenshot 2024-08-14 091147.png

 

Screenshot 2024-08-14 092100.png

^This picture above I want to do the increments for the WALLID but not other two sides. I would like to retain the NAILLENGTH & NAILID attributes if possible.

 

Screenshot 2024-08-14 092253.png

 

 

 

0 Likes
1,079 Views
9 Replies
Replies (9)
Message 2 of 10

ec-cad
Collaborator
Collaborator

That can be done. Could you post a simple drawing, saved to R2013 or R2021, for testing ?

Questions to answer.

Do you want to 'pick each block in order.. or select several with a starting #.

Are they always to be (3) digits (string length of 3), for the WallID ?

 

ECCAD

0 Likes
Message 3 of 10

MaliktheOne
Contributor
Contributor

Hello,

 

Thank you for your help.

 

I've attached the files related to the question. I have sent a Pile ID block file that I am wanted to increment and the sample drawing (blue circles indicating piles) of what I would like to ID with using the block (PILEIDBLOCK).

 

I would like to pick each block in order when placing them.

 

No they are not in three digits for the WALLID, I would like for them to start with single digits. For example. 1 ,2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... so on. 

0 Likes
Message 4 of 10

ec-cad
Collaborator
Collaborator

OK, a couple of more questions / comments.

The 'blockname' that contains the WALLID attribute is called "UMA15FTNAIL" - correct ?

And, you said: "I would like to pick each block in order when placing them." , does that mean

they are already in the drawing (pick each block) .. or you are going to add them to the

drawing (when placing them) .. ?

IF you intend to 'insert' the drawing "PileIDBlock.dwg" , it will have to be inserted (once) and

then deleted, so the Block "UMA15FTNAIL" is exposed for further inserts.

Alternately, you could just 'insert' that block by it's 'name', once it's in the target drawing.

So, I need to know if there are already blocks inserted, or you need to insert them, and increment

the WALLID attribute.

 

Sorry to be such a bother, but it will make a difference in the Code ...

 

ECCAD

 

0 Likes
Message 5 of 10

MaliktheOne
Contributor
Contributor

The 'blockname' that contains the WALLID attribute is called "UMA15FTNAIL" - correct ?

Yes 

 

And, you said: "I would like to pick each block in order when placing them." , does that mean

they are already in the drawing (pick each block) .. or you are going to add them to the

drawing (when placing them) .. ?

 

Yes the blocks are already in the drawing and I would like to select them all and do the increment numbering. 

 

 

No problem at all. I hope my answer is clear.

 

Ideally, when labeling my piles, I would use the block I shared and place it on the piles I’ve organized. I would like the block to automatically number the WALLID attribute while keeping the other attributes (NAILID and NAILLENGTH) intact so that I can adjust them individually if their ID or length varies. 

 

Hopefully this gives more clarity to what I am doing. 

Screenshot 2024-08-14 121445.png

 

0 Likes
Message 6 of 10

ec-cad
Collaborator
Collaborator

Well, here's more issues. Since you have a 'nested' block within that main block ...

Remaining issues:
You said "Yes the blocks are already in the drawing and I would like to select them all and do
the increment numbering."

First issue is "I would like to select them all and do the increment numbering."
That implies you need to select 'all' blocks by that name. It depends on how you
pick that selection set. It can be truly 'All', and they would be incremented, the
question is, will they be in the 'order' you want, probably not.
If the selection set is picked by 'Window' or 'Crossing', the same applies. They may
not come out say top to bottom, right to left, etc. They will get incremented.
In order to make them sequential, AND in the order you want, you will have to pick each
block, in the order you want.

Question: Which 'block' did you insert there, I assume it was the "pileidblock" ?

If so, the following 'Explanation' applies.


Explanation:

When I do a List on the block "pileidblock" I get:

BLOCK REFERENCE Layer: "0"
Space: Model space
Handle = 2d5
Block Name: "pileidblock"
at point, X= 327.1310 Y= 78.9946 Z= 0.0000
X scale factor: 1.0000
Y scale factor: 1.0000
rotation angle: 0
Z scale factor: 1.0000
InsUnits: Inches
Unit conversion: 1.0000
Scale uniformly: No
Allow exploding: Yes

 

[After I explode the above block], it exposes a 'nested' block called "UMA15FTNAIL"

When I list that block, I get:
BLOCK REFERENCE Layer: "UM SYMBOLS"
Space: Model space
Handle = 2cf
Block Name: "UMA15FTNAIL"
at point, X= 326.5220 Y= 83.1370 Z= 0.0000
X scale factor: 1.0000
Y scale factor: 1.0000
rotation angle: 0
Z scale factor: 1.0000
InsUnits: Inches
Unit conversion: 1.0000
Scale uniformly: Yes
Allow exploding: Yes

ATTRIBUTE Layer: "UM MODEL SYMBOLS"
Space: Model space
Handle = 2d0
Style = "J"
Annotative: No
Typeface = Arial
end point, X= 326.1808 Y= 83.1495 Z= 0.0000
height 0.7500
value 001
tag WALLID                 <---------------------
rotation angle 0
width scale factor 1.0000
obliquing angle 0
flags normal
generation normal
........ more Attributes follow:

 

Note, the Attribute you want to Increment, is "WALLID", as shown above.

So, in order to set the increment # (string), into that Attribute's 'TextString Property
it must be 'unnested' from the main block "pileidblock" so it can be modified / updated.

IF you were to insert the block "UMA15FTNAIL" - instead of the main block "pileidblock",
we can change it readily. IF you still want to use the main block, then we would have
to 'explode' it, so it surfaces the nested block. And, you would have to 'repick' that
unnested block.

 

The program (could), just boldly go ahead and 'explode' all the "pileidblock" 's in the drawing,
that would 'surface' all the nested blocks within, and they would be pickable at that point.
Is that what you want to do ?

 

In summary, I think the approach would be to:

Select all the 'pileidblock' blocks, explode them (surfacing the nested block),

then set the increment #, by prompting you for it.

Next, while you pick each block seperatly, increment it, then you select the next block.

IF you pick nothing, ends the routine. You can Zoom / Pan around, then run the program again,

and so on.

Would that be what you need ?

 

ECCAD

0 Likes
Message 7 of 10

MaliktheOne
Contributor
Contributor

Thank you so much for your explanation. 

 

I believe your approach may be the best method for this application that I am trying to do.  

0 Likes
Message 8 of 10

ec-cad
Collaborator
Collaborator

Sorry for the delay, been busy. 🙂

Here's the Lisp (lightly tested).

Save the test.lsp in a temp folder. e.g. C:\temp

In AutoCAD, to load it, at Command Line, type in:

(load "c:\\temp\\test.lsp") <Enter Key>

To 'run' the program, at the Command Line, type in:

TEST <Enter Key>

It will ask you for a beginning #, then pick blocks to increment..

Cheers:

🙂

;; test.lsp
;; Function: to 'pick a certain block, and increment a certain attribute value.
;; Since there may be 'nested' block 'UMA15FTNAIL' inside inserted blocks 'PileIDBlock',
;;  explode those first.

(defun C:TEST ()
  (setq ss nil)
  (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 "pileidblock"))))
  (if ss
   (command "_explode" ss ""); explode blocks
  ); if
; Get a Starting Number
   (setq inc (getint "\nInput a Starting WallID # :"))
   (if inc
    (setq inc (- inc 1))
   ); if
; Select a Block, if it's name is "UMA15FTNAIL", Increment it's WALLID Value
 (while
   (setq blk (entsel "\nPick a Block, or Hit Enter Key to quit:"))
   (if blk
    (progn
     (setq ent (car blk))
     (setq elist (cdr (entget ent))); entity list
     (setq bn (cdr (assoc 2 elist))); blockname
     (if (= bn "UMA15FTNAIL")
      (progn
       (setq obj (vlax-ename->vla-object ent))
        (foreach att (vlax-invoke Obj 'GetAttributes)
         (if (= (vla-get-Tagstring att) "WALLID")
          (progn
           (setq inc (+ inc 1))
           (setq Att_Value (itoa inc))
           (vla-put-textstring att Att_Value)
          ); progn
         ); if
       ); foreach
      ); progn
      (prompt "\nWrong Blockname, try again:")
     ); if
   ); progn
  ); if blk
 ); while
); defun
(princ "\nType TEST to run this program")
(princ)

 

ECCAD

0 Likes
Message 9 of 10

MaliktheOne
Contributor
Contributor

Thank you so much for the assistance. Thid will definitely help me when I am numbering my piles.

 

0 Likes
Message 10 of 10

ec-cad
Collaborator
Collaborator

I see a little OOPs in the original Lisp. It wasn't exploding the group 'ss , that needed

to be done on each item of the selection set, so I changed that portion.

 

Here's the corrected version.

 

ECCAD

0 Likes