Community
AutoCAD MEP Forum
Welcome to Autodesk’s AutoCAD MEP Forums. Share your knowledge, ask questions, and explore popular AutoCAD MEP topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Count devices via VBA

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
339 Views, 2 Replies

Count devices via VBA

I want to do a quick count of devices in a drawing
and I want to do it via VBA, but I'm running into a wall on how to do
it.

(I know I can create a schedule, but I don't want
to)

 

 

Here's what I have so far...

 

Public Sub CountDevices()
   
Dim objDeviceStyle As AecbDeviceStyle
    Dim objDeviceStyles
As AecbDeviceStyles
    Dim aecDB As New
AecbDatabase
   
    aecDB.Init
ThisDrawing.Database
    Set objDeviceStyles =
aecDB.DeviceStyles
   
    For Each
objDeviceStyle In objDeviceStyles
       
If objDeviceStyle.Name <> "Standard"
Then
           
Debug.Print objDeviceStyle.Name
       
End If
    Next objDeviceStyle
End Sub

 

I can't quite figure out how to get the total
count for each "objDeviceStyle".

I know it's something easy, but I'm just gonna
chalk it up to it being a Monday.  🙂

 

Thanks in advance!


--
Matt W
 
There are 3 kinds
of people:
  Those who can count, and those who
can't.
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

Hi Matt!

 

The Code you have produced works fine when it comes
to identifying the device styles that exist in the drawing, imported styles,
inserted or not. However, if you want to scan the drawing of how many devices
there is in it you will need to search through the modelspace or
dictionaries databases. The easiest way (in my experience) is to scan
through the modelspace, you will then only get the devices that are actually
inserted into the drawing. If you look at my VBA project below the header DEVICE
COUNT in the autodesk.autocad.customer-files newsgrop (a part of a discussion I
had about Device Counting in the BS wishes discussion newsgroup), you might find
it useful, it counts the presence of devices and groups them by system and
style.

 

The basic syntax I usually use is the
following: (Prints the stylename for everey ocurrance)

 

Public Sub CountDevices()
Dim obj As
AcadObject
Dim aDevice As AecbDevice

 

For Each obj In
Application.ActiveDocument.Database.ModelSpace
    If TypeOf
obj Is AecbDevice Then 

        Set
aDevice = obj
        Debug.Print
aDevice.StyleName
    End If
Next obj
End
Sub

 

I hope this helps

 

/Hakan Wikemar



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

I want to do a quick count of devices in a
drawing and I want to do it via VBA, but I'm running into a wall on how to do
it.

(I know I can create a schedule, but I don't
want to)

 

 

Here's what I have so far...

 

Public Sub CountDevices()
   
Dim objDeviceStyle As AecbDeviceStyle
    Dim
objDeviceStyles As AecbDeviceStyles
    Dim aecDB As New
AecbDatabase
   
    aecDB.Init
ThisDrawing.Database
    Set objDeviceStyles =
aecDB.DeviceStyles
   
    For Each
objDeviceStyle In
objDeviceStyles
        If
objDeviceStyle.Name <> "Standard"
Then
           
Debug.Print objDeviceStyle.Name
       
End If
    Next objDeviceStyle
End Sub

 

I can't quite figure out how to get the total
count for each "objDeviceStyle".

I know it's something easy, but I'm just gonna
chalk it up to it being a Monday.  🙂

 

Thanks in advance!


--
Matt W
 
There are 3 kinds
of people:
  Those who can count, and those who
can't.
Message 3 of 3
Anonymous
in reply to: Anonymous

Ah ha!!

I knew I needed some kind of an
array.

 

I took a look at your code in the CF group and
that's exactly what I was looking to do (and then some).

 

Thanks, Hakan!


--
Matt W
 
There are 3 kinds of people:
  Those
who can count, and those who can't.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Hi Matt!

 

The Code you have produced works fine when it
comes to identifying the device styles that exist in the drawing, imported
styles, inserted or not. However, if you want to scan the drawing of how many
devices there is in it you will need to search through the modelspace or
dictionaries databases. The easiest way (in my experience) is to
scan through the modelspace, you will then only get the devices that are
actually inserted into the drawing. If you look at my VBA project below the
header DEVICE COUNT in the autodesk.autocad.customer-files newsgrop (a part of
a discussion I had about Device Counting in the BS wishes discussion
newsgroup), you might find it useful, it counts the presence of devices and
groups them by system and style.

 

The basic syntax I usually use is the
following: (Prints the stylename for everey ocurrance)

 

Public Sub CountDevices()
Dim obj As
AcadObject
Dim aDevice As AecbDevice

 

For Each obj In
Application.ActiveDocument.Database.ModelSpace
    If TypeOf
obj Is AecbDevice Then 

        Set
aDevice = obj
        Debug.Print
aDevice.StyleName
    End If
Next obj
End
Sub

 

I hope this helps

 

/Hakan Wikemar



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

I want to do a quick count of devices in a
drawing and I want to do it via VBA, but I'm running into a wall on how to
do it.

(I know I can create a schedule, but I don't
want to)

 

 

Here's what I have so far...

 

Public Sub
CountDevices()
    Dim objDeviceStyle As
AecbDeviceStyle
    Dim objDeviceStyles As
AecbDeviceStyles
    Dim aecDB As New
AecbDatabase
   
    aecDB.Init
ThisDrawing.Database
    Set objDeviceStyles =
aecDB.DeviceStyles
   
    For Each
objDeviceStyle In
objDeviceStyles
        If
objDeviceStyle.Name <> "Standard"
Then
           
Debug.Print
objDeviceStyle.Name
        End
If
    Next objDeviceStyle
End Sub

 

I can't quite figure out how to get the total
count for each "objDeviceStyle".

I know it's something easy, but I'm just gonna
chalk it up to it being a Monday.  🙂

 

Thanks in advance!


--
Matt W
 
There are 3
kinds of people:
  Those who can count, and those who
can't.

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

Post to forums  

Autodesk Design & Make Report

”Boost