TheSwamp

Code Red => VB(A) => Topic started by: David Hall on May 01, 2006, 01:05:59 PM

Title: block count
Post 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.

Code: [Select]
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
Title: Re: block count
Post by: Chuck Gabriel on May 01, 2006, 01:16:23 PM
You could use a filtered selection set to get the count of all insertions in all layouts (not including those nested in other blocks).
Title: Re: block count
Post by: Jeff_M on May 01, 2006, 01:37:22 PM
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.
Title: Re: block count
Post by: David Hall on May 01, 2006, 02:03:16 PM
this is how far Ive gotten, but it keeps erroring out
Code: [Select]
    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
Title: Re: block count
Post by: David Hall on May 01, 2006, 02:04:08 PM
I also tried
DATAVALUE(0) = "INSERT"

but that didn't work either
Title: Re: block count
Post by: Chuck Gabriel on May 01, 2006, 02:10:35 PM
Code: [Select]
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
Title: Re: block count
Post by: David Hall on May 01, 2006, 02:16:13 PM
thanks guys, I dont know why I couldn't remember that.