Author Topic: block count  (Read 3090 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
block count
« 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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Chuck Gabriel

  • Guest
Re: block count
« Reply #1 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).

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: block count
« Reply #2 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.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: block count
« Reply #3 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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: block count
« Reply #4 on: May 01, 2006, 02:04:08 PM »
I also tried
DATAVALUE(0) = "INSERT"

but that didn't work either
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Chuck Gabriel

  • Guest
Re: block count
« Reply #5 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

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: block count
« Reply #6 on: May 01, 2006, 02:16:13 PM »
thanks guys, I dont know why I couldn't remember that.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)