@zka192020 Hi,
here below a sample code for inserting a number "over" the block, with "over" I mean that it's untied with block, like as attribute could be.
Before execute the code you have to explode your associative array, and in case you create a new one, please not set it as associative.
Code could be refined, for example you can check the insertion point of block and if the value of Y changes, you can restart the count.
Please note that the number sequence associated to block will be the same as insertion block sequence.
I hope this will helps you a little bit.
Bye
Sub Countblock()
A = 1
Dim MyTextInsPoint(0 To 2) As Double
Dim MyAlignmentPoint(0 To 2) As Double
Dim MyblockInsPoint() As Double
Dim MyBObject As Object
For Each MyBObject In ThisDrawing.ModelSpace
If TypeOf MyBObject Is AcadBlockReference Then
Set MyblockNew = MyBObject
MyblockInsPoint = MyblockNew.InsertionPoint
'midpoint X = (X1 + X2) / 2
'midpoint Y = (Y1 + Y2) / 2
'midpoint Z = (Z1 + Z2) / 2
MyblockNew.GetBoundingBox minExt, maxExt
MyTextInsPoint(0) = (minExt(0) + maxExt(0)) / 2#
MyTextInsPoint(1) = (minExt(1) + maxExt(1)) / 2#
MyTextInsPoint(2) = 0# '(minExt(2) + maxExt(2)) / 2#
Set MyText = ThisDrawing.ModelSpace.AddText(CStr(A), MyTextInsPoint, 180)
MyText.Alignment = acAlignmentMiddleCenter
MyAlignmentPoint(0) = MyTextInsPoint(0)
MyAlignmentPoint(1) = MyTextInsPoint(1)
MyAlignmentPoint(2) = MyTextInsPoint(2)
MyText.TextAlignmentPoint = MyAlignmentPoint
MyText.Alignment = acAlignmentTopCenter
ThisDrawing.Regen acAllViewports
A = A + 1
End If
Next
End Sub