Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

RE: [V8i] Count Elements in Each Model?

$
0
0

Hi Brahms,

[quote user="Brahms"]there will be no references[/quote]

It makes the macro simpler :-)

[quote user="Brahms"]The purpose is to determine which of the models contains any elements[/quote]

If your purpose is to test if there are some graphical elements in a model, you don't have to count them.

You can do it this way. In fact the most of the code is just an output, the core is to check Count property of GraphicalElementCache.

Option Explicit

Public Sub ProcessDesignFile()
    Dim model As ModelReference

    For Each model In ActiveDesignFile.Models
        Dim isEmpty As Boolean
        isEmpty = IsModelEmpty(model)
        PrintMessage model.Name, isEmpty
    Next
End Sub

Private Function IsModelEmpty(model As ModelReference) As Boolean
    If model.GraphicalElementCache.Count = 0 Then
        IsModelEmpty = True
    Else
        IsModelEmpty = False
    End If
End Function

Private Sub PrintMessage(modelName As String, isEmpty As Boolean)
    Dim message As String
    message = "Model " & modelName & " " & GetVerb(isEmpty) & " empty."

    MessageCenter.AddMessage message, vbNullString, msdMessageCenterPriorityInfo, False
End Sub

Private Function GetVerb(isEmpty As Boolean) As String
    If isEmpty Then
        GetVerb = "is"
    Else
        GetVerb = "is not"
    End If
End Function

With regards,

  Jan


Viewing all articles
Browse latest Browse all 7260

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>