VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Counting Blocks with similar names

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
141 Views, 4 Replies

Counting Blocks with similar names

This is more of a database question but here goes: I think it is pretty
basic.
I am using VBA/ADO to count the number of blocks in a drawing. I am trying
to count (or sum) the number of blocks whose names begin with "S_" (e.g.
S_1, S_2, S_3). E.g., if there are three of each of the blocks, the sum
would be nine.
Can anyone help?
Thanks.....Sean
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Hi Sean,
When you say "database question", do you mean "the drawing database" or
an external db? In the drawing, you can iterate the modelspace
collection and check for instances of "acadblockreference" with a name
that starts with "S". Since your checking instances, it will return a
valid count including duplicates.
-Josh

Sean wrote:

> This is more of a database question but here goes: I think it is pretty
> basic.
> I am using VBA/ADO to count the number of blocks in a drawing. I am trying
> to count (or sum) the number of blocks whose names begin with "S_" (e.g.
> S_1, S_2, S_3). E.g., if there are three of each of the blocks, the sum
> would be nine.
> Can anyone help?
> Thanks.....Sean
>
>
>
Message 3 of 5
Anonymous
in reply to: Anonymous

Use a filtered selection set:

Dim ss As AcadSelectionSet
Dim fType, fData

Set ss = CreateSelectionSet
BuildFilter 0, "INSERT", 2, "S_*"
ss.Select acSelectionSetAll, , , fType, fData
Debug.Print "Total blocks = " & ss.Count

See the VB section of my site for the CreateSelectionSet and BuildFilter
functions.

--
http://www.acadx.com

Good judgement comes from experience.
Experience comes from bad judgement.


"Sean" wrote in message
news:B3CA88363A616A28E91A1DCE05D58CD5@in.WebX.maYIadrTaRb...
> This is more of a database question but here goes: I think it is pretty
> basic.
> I am using VBA/ADO to count the number of blocks in a drawing. I am trying
> to count (or sum) the number of blocks whose names begin with "S_" (e.g.
> S_1, S_2, S_3). E.g., if there are three of each of the blocks, the sum
> would be nine.
> Can anyone help?
> Thanks.....Sean
>
>
Message 4 of 5
Anonymous
in reply to: Anonymous

thanks to you both. cheers

"Frank Oquendo" wrote in message
news:32ADB364C389B1C5AD456762BFA5CBB4@in.WebX.maYIadrTaRb...
> Use a filtered selection set:
>
> Dim ss As AcadSelectionSet
> Dim fType, fData
>
> Set ss = CreateSelectionSet
> BuildFilter 0, "INSERT", 2, "S_*"
> ss.Select acSelectionSetAll, , , fType, fData
> Debug.Print "Total blocks = " & ss.Count
>
> See the VB section of my site for the CreateSelectionSet and BuildFilter
> functions.
>
> --
> http://www.acadx.com
>
> Good judgement comes from experience.
> Experience comes from bad judgement.
>
>
> "Sean" wrote in message
> news:B3CA88363A616A28E91A1DCE05D58CD5@in.WebX.maYIadrTaRb...
> > This is more of a database question but here goes: I think it is pretty
> > basic.
> > I am using VBA/ADO to count the number of blocks in a drawing. I am
trying
> > to count (or sum) the number of blocks whose names begin with "S_" (e.g.
> > S_1, S_2, S_3). E.g., if there are three of each of the blocks, the sum
> > would be nine.
> > Can anyone help?
> > Thanks.....Sean
> >
> >
>
>
Message 5 of 5
Anonymous
in reply to: Anonymous

Typo alert. Replace the call to BuildFilter:

BuildFilter fType, fData, 0, "INSERT", 2, "S_*"

--
http://www.acadx.com

Good judgement comes from experience.
Experience comes from bad judgement.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report