Message 1 of 6
Counting specific blocks

Not applicable
04-24-2006
09:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am having a problem counting blocks in a drawing. When the user inserts a block, I want the vba program to count how many similar blocks are in the drawing. I can accomplish part of this, but I hit two different snags. This first is the accuracy of the block count. I am tyring to use a filtered selection set to gather all of the blocks. I am using the filter type of "insert", but it doesn't seem to count all the block references? The example drawing I am testing this on contains 55 of these blocks but the count shows up as 13. If a block alread in the drawing gets copied instead of inserted, does this mess up the count? I have been using the (entget (car (entsel))) command to determine the type and name and the name seems to change sometimes after you copy the block. For example, after running the lsp on an inserted block, item 2 is "Trane FC-04". If I copy that block then run the lsp on the copied block, item 2 is still the same, but if the block is copied and then rotated, item 2 is "*U2335". But under autocad properties, the name still shows as "Trane FC-04". Why does this change? My second snag is selecting similar blocks since the same basic block has 2 or 3 sizes. The block names all start out similar so I am trying to utilize the Like method. This is also, not returning a correct number of blocks. Am I going about this the wrong way? I have included some of my code below. Thanks for your help.
Jason
Grps(0) = 0: Dats(0) = "Block Reference"
Grps(1) = 2: Dats(1) = ""
On Error Resume Next
Set SS = ThisDrawing.SelectionSets.Add("SS")
If Err.Number <> 0 Then
Set SS = ThisDrawing.SelectionSets.Item("SS")
End If
SS.Clear
match1 = "*" & Left(NewBlk.Name, 9) & "*"
Dats(1) = match1
Filter1 = Grps
Filter2 = Dats
SS.Select acSelectionSetAll, , , Filter1, Filter2
intBlockCounter = SS.count
Message was edited by: test_52
Message was edited by: test_52 Message was edited by: test_52
Jason
Grps(0) = 0: Dats(0) = "Block Reference"
Grps(1) = 2: Dats(1) = ""
On Error Resume Next
Set SS = ThisDrawing.SelectionSets.Add("SS")
If Err.Number <> 0 Then
Set SS = ThisDrawing.SelectionSets.Item("SS")
End If
SS.Clear
match1 = "*" & Left(NewBlk.Name, 9) & "*"
Dats(1) = match1
Filter1 = Grps
Filter2 = Dats
SS.Select acSelectionSetAll, , , Filter1, Filter2
intBlockCounter = SS.count
Message was edited by: test_52
Message was edited by: test_52 Message was edited by: test_52