TheSwamp
Code Red => VB(A) => Topic started by: David Hall on May 01, 2006, 01:05:59 PM
-
OK, so my brain must be on holiday, I cant remember how to count blocks in a dwg. I keep getting the count of the objects that block is made up of.
Sub COUNTT()
Dim OBJBLK As AcadBlocks
Set OBJBLK = ThisDrawing.Blocks
MsgBox "THERE ARE " & OBJBLK.Count & " B OBJS" <------------ this counts all blocks in dwg
Dim I As Integer
Dim OBJB As AcadBlockReference
'Set OBJB = OBJBLK.Item("HAIRPIN60").Count <----------this dows nothing
I = OBJBLK.Item("HAIRPIN60").Count <------- this errors also
End Sub
-
You could use a filtered selection set to get the count of all insertions in all layouts (not including those nested in other blocks).
-
ObjBlock.Count only refers to how many items are in the block.......
For a simple count, Chuck's approach works well.
For nested blocks, first iterate each non-layout block looking for the inserted block name and add that block and the number of times it occurs to a collection. Then iterate the layouts look ing for the main block AND any of those obtained in the first step, mulitply by the # of times it occured in that block, to get an overall count......this can be tricky with many nested blocks.
-
this is how far Ive gotten, but it keeps erroring out
Dim GPCODE As Integer
Dim DATAVALUE(1) As Variant
GPCODE = 0
DATAVALUE(0) = "AcDbBlockReference"
DATAVALUE(1) = "HAIRPIN60"
Set OBJSELSET = ThisDrawing.SelectionSets.Add("BLKCOUNT")
OBJSELSET.Select acSelectionSetAll, , , GPCODE, DATAVALUE
-
I also tried
DATAVALUE(0) = "INSERT"
but that didn't work either
-
Dim filterType(0) as Integer
Dim filterData(0) as Variant
Dim selSet as AcadSelectionSet
filterType(0) = 2 : filterData(0) = "HAIRPIN60"
selSet = ThisDrawing.SelectionSets.Add("BLKCOUNT")
selSet.Select acSelectionSetAll, , , filterType, filterData
-
thanks guys, I dont know why I couldn't remember that.