Hello,
I am trying to write a macro that counts the number of elements in each model of a drawing. The purpose is to determine which of the models contains any elements if any so that I can print a PDF of which ever model contains something and skip the ones that are empty models. Most of my drawings contain a Default model (which may or may not be empty) and a second sheet model (which also may or may not be empty).
Currently this is what I have below. It works but I think I have the element array counter wrong because it counts the same amount of elements in the second sheet model as in the Default model. Even if the Default model contains 10 elements total, and the second sheet model contains only 1.
Sub CountElements() Dim ModelRef As ModelReference Dim FileName As String Dim TextFile As Integer Dim Message As String Dim Counter As Integer Dim ModelCount As Integer Dim ModelArrayName(10) Dim ElementArrayCounter(10) Dim myEnum As ElementEnumerator Dim myFilter As New ElementScanCriteria Dim i As Integer FileName = ActiveDesignFile.Name TextFile = FreeFile ModelCount = ActiveDesignFile.Models.Count Open "C:\Temp\Bentley\CountElements_" & Format(Time, "Hh-Nn-Ss") & ".txt" For Append As #TextFile myFilter.ExcludeAllTypes myFilter.IncludeType msdElementTypeArc myFilter.IncludeType msdElementTypeComplexShape myFilter.IncludeType msdElementTypeComplexString myFilter.IncludeType msdElementTypeCone myFilter.IncludeType msdElementTypeCurve myFilter.IncludeType msdElementTypeDimension myFilter.IncludeType msdElementTypeEllipse myFilter.IncludeType msdElementTypeLine myFilter.IncludeType msdElementTypeLineString myFilter.IncludeType msdElementTypeMultiLine myFilter.IncludeType msdElementTypeReferenceAttachment myFilter.IncludeType msdElementTypeShape myFilter.IncludeType msdElementTypeSharedCell myFilter.IncludeType msdElementTypeSolid myFilter.IncludeType msdElementTypeSurface myFilter.IncludeType msdElementTypeTag myFilter.IncludeType msdElementTypeText myFilter.IncludeType msdElementTypeTextNode For Each ModelRef In ActiveModelReference.DesignFile.Models ModelArrayName(i) = ModelRef.Name Set myEnum = ActiveModelReference.Scan(myFilter) While myEnum.MoveNext ElementArrayCounter(i) = ElementArrayCounter(i) + 1 Debug.Print ElementArrayCounter(0) Debug.Print ElementArrayCounter(1) Wend Counter = Counter + 1 i = Counter Next Close #TextFile 'Debug.Print ModelArrayName(0) & " contains " & ElementArrayCounter(0) & " elements."'Debug.Print ModelArrayName(1) & " contains " & ElementArrayCounter(1) & " elements." End Sub
Any help here would be much appreciated. Thanks.