Hi everyone,
I have recently started to delve into VBA along with Autocad He is my beginner code that should count blocks in an autocad drawing. However, only the block names are placed in ListBox1 and a 0 count for all of them in ListBox2.
Can anyone see a reason?
Sub CommandButton1_Click()
Dim i, j, btot As Integer
Dim bnam As String
Dim ent As Object
btot = ThisDrawing.Blocks.Count
For i = 0 To btot - 1
bnam = ThisDrawing.Blocks.Item(i).Name
If Not Mid$(bnam, 1, 1) = "*" Then ListBox1.AddItem bnam
Next i
For i = 0 To ListBox1.ListCount - 1
bnam = ListBox1.List(i): btot = 0
For j = 0 To ThisDrawing.ModelSpace.Count - 1
Set ent = ThisDrawing.ModelSpace.Item(j)
If ent.EntityType = acBlockReference And ent.Name = banam Then btot = btot + 1
Next j
ListBox2.AddItem btot
Next i
End Sub
I have recently started to delve into VBA along with Autocad He is my beginner code that should count blocks in an autocad drawing. However, only the block names are placed in ListBox1 and a 0 count for all of them in ListBox2.
Can anyone see a reason?
Sub CommandButton1_Click()
Dim i, j, btot As Integer
Dim bnam As String
Dim ent As Object
btot = ThisDrawing.Blocks.Count
For i = 0 To btot - 1
bnam = ThisDrawing.Blocks.Item(i).Name
If Not Mid$(bnam, 1, 1) = "*" Then ListBox1.AddItem bnam
Next i
For i = 0 To ListBox1.ListCount - 1
bnam = ListBox1.List(i): btot = 0
For j = 0 To ThisDrawing.ModelSpace.Count - 1
Set ent = ThisDrawing.ModelSpace.Item(j)
If ent.EntityType = acBlockReference And ent.Name = banam Then btot = btot + 1
Next j
ListBox2.AddItem btot
Next i
End Sub