AutoCAD MEP General Discussion

AutoCAD MEP General Discussion

Reply
*W, Matt
Message 1 of 3 (158 Views)

Count devices via VBA

158 Views, 2 Replies
11-24-2003 12:10 AM
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.  :smileyhappy:

 

Thanks in advance!


--
Matt W
 
There are 3 kinds
of people:
  Those who can count, and those who
can't.
*[Autodesk], Hakan Wikemar
Message 2 of 3 (158 Views)

Re: Count devices via VBA

11-24-2003 04:36 PM in reply to: *W, Matt
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.  :smileyhappy:

 

Thanks in advance!


--
Matt W
 
There are 3 kinds
of people:
  Those who can count, and those who
can't.
*W, Matt
Message 3 of 3 (158 Views)

Re:

11-24-2003 09:35 PM in reply to: *W, Matt
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.  :smileyhappy:

 

Thanks in advance!


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

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions to get help installing your software.

New AutoCAD MEP Category!

The AutoCAD MEP forum has moved into it's very own category page, and can no longer be found within the Additional Product Forums.