Sub Main Dim aDoc As AssemblyDocument = TryCast(ThisApplication.ActiveDocument, AssemblyDocument) If IsNothing(aDoc) Then Logger.Debug("Not Run In Assembly Document") : Exit Sub iLogicVb.Automation.LogControl.Level = LogLevel.Trace Dim FeatureTypesToCount As New List(Of ObjectTypeEnum) FeatureTypesToCount.AddRange({ObjectTypeEnum.kExtrudeFeatureObject, ObjectTypeEnum.kSweepFeatureObject, ObjectTypeEnum.kCombineFeatureObject }) Dim WorkObjectsToCount As New List(Of String) WorkObjectsToCount.AddRange({"WorkPoint", "WorkAxis", "WorkPlane", "WorkSurface", "UCS" }) Dim OtherObjectsToCount As New List(Of String) OtherObjectsToCount.AddRange({"Sketch", "Sketch3D" }) 'Anything added needs manual programming in Function: "GetOtherObjectCount" Dim TotalcountingMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap TotalcountingMap = CountAssemblyFeatures(aDoc, WorkObjectsToCount, OtherObjectsToCount, FeatureTypesToCount, TotalcountingMap, 1) For Each refDoc As Document In aDoc.ReferencedDocuments Dim OccurrenceCount As Integer = aDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(refDoc).Count If OccurrenceCount < 1 Then Continue For If refDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject TotalcountingMap = CountAssemblyFeatures(refDoc, WorkObjectsToCount, OtherObjectsToCount, FeatureTypesToCount, TotalcountingMap, OccurrenceCount) Else If refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject TotalcountingMap = CountPartFeatures(refDoc, WorkObjectsToCount, OtherObjectsToCount, FeatureTypesToCount, TotalcountingMap, OccurrenceCount) End If Next Call ExportResults(aDoc.DisplayName, TotalcountingMap) Call iLogicLogToText End Sub Sub iLogicLogToText Dim tempFileName As String = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), ".txt") iLogicVb.Automation.LogControl.SaveLogAs(tempFileName) Dim AllLogText As String = System.IO.File.ReadAllText(tempFileName) Dim MarkerString As String = ": >>---------------------------" Dim MarkerIndex As Integer = AllLogText.LastIndexOf(MarkerString) + MarkerString.Length+2 System.IO.File.WriteAllText(tempFileName, AllLogText.Substring(MarkerIndex)) Shell("notepad.exe " & tempFileName, vbNormalFocus) End Sub Sub ExportResults(DocDisplayName As String, countedMap As NameValueMap) Logger.Trace(DocDisplayName & " Feature Counts:") For i = 1 To countedMap.Count If countedMap.Value(countedMap.Name(i)) < 1 Then Continue For 'Excludes lines for 0 results Logger.Trace(" " & countedMap.Name(i) & ": " & countedMap.Value(countedMap.Name(i)).ToString) Next End Sub Function CountPartFeatures(pDoc As PartDocument, WorkObjectsToCount As List(Of String), OtherObjectsToCount As List(Of String), FeatureTypesToCount As List(Of ObjectTypeEnum), TotalcountingMap As NameValueMap, multiplier As Integer) As NameValueMap Dim countingMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap For Each s As String In WorkObjectsToCount countingMap.Add(s, GetWorkObjectCount(s, pDoc)) Next For Each s As String In OtherObjectsToCount countingMap.Add(s, GetOtherObjectCount(s, pDoc)) Next For Each ObjTypeEnum As ObjectTypeEnum In FeatureTypesToCount Dim StrippedName As String = Mid(CType(ObjTypeEnum, ObjectTypeEnum).ToString, 2, CType(ObjTypeEnum, ObjectTypeEnum).ToString.Length-7) countingMap.Add(StrippedName, pDoc.ComponentDefinition.Features.OfType(Of PartFeature).Where(Function(d) d.Type = ObjTypeEnum).Count) Next 'Call ExportResults(pDoc.DisplayName, countingMap) For i = 1 To countingMap.Count countingMap.Value(countingMap.Name(i)) *= multiplier Next Return JoinTheseMaps(TotalcountingMap, countingMap) End Function Function CountAssemblyFeatures(aDoc As AssemblyDocument, WorkObjectsToCount As List(Of String), OtherObjectsToCount As List(Of String), FeatureTypesToCount As List(Of ObjectTypeEnum), TotalcountingMap As NameValueMap, multiplier As Integer) As NameValueMap Dim countingMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap For Each s As String In WorkObjectsToCount countingMap.Add(s, GetWorkObjectCount(s, aDoc)) Next For Each s As String In OtherObjectsToCount countingMap.Add(s, GetOtherObjectCount(s, aDoc)) Next For Each ObjTypeEnum As ObjectTypeEnum In FeatureTypesToCount Dim StrippedName As String = Mid(CType(ObjTypeEnum, ObjectTypeEnum).ToString, 2, CType(ObjTypeEnum, ObjectTypeEnum).ToString.Length-7) countingMap.Add(StrippedName, aDoc.ComponentDefinition.Features.OfType(Of PartFeature).Where(Function(d) d.Type = ObjTypeEnum).Count) Next 'Call ExportResults(aDoc.DisplayName, countingMap) For i = 1 To countingMap.Count countingMap.Value(countingMap.Name(i)) *= multiplier Next Return JoinTheseMaps(TotalcountingMap, countingMap) End Function Function JoinTheseMaps(PrimaryMap As NameValueMap, SecondaryMap As NameValueMap) As NameValueMap Dim Matched As Boolean = False For i = 1 To SecondaryMap.Count For j = 1 To PrimaryMap.Count If SecondaryMap.Name(i) <> PrimaryMap.Name(j) Then Matched = False : Continue For PrimaryMap.Value(PrimaryMap.Name(j)) += SecondaryMap.Value(SecondaryMap.Name(i)) Matched = True Exit For Next If Not Matched Then PrimaryMap.Add(SecondaryMap.Name(i), SecondaryMap.Value(SecondaryMap.Name(i))) Next Return PrimaryMap End Function Function GetWorkObjectCount(ObjectName As String, Doc As Document) As Integer Select Case ObjectName Case "WorkPoint" Return Doc.ComponentDefinition.WorkPoints.Count-1 Case "WorkAxis" Return Doc.ComponentDefinition.WorkAxes.Count-3 Case "WorkPlane" Return Doc.ComponentDefinition.WorkPlanes.Count-3 Case "WorkSurface" Try Return Doc.ComponentDefinition.WorkSurfaces.Count Catch Return 0 'WorkSurfaceObject Doesn't exist for assemblies End Try Case "UCS" Return Doc.ComponentDefinition.UserCoordinateSystems.Count End Select Logger.Debug(ObjectName & " not setup in Function: ""GetWorkObjectCount""") Return 0 End Function Function GetOtherObjectCount(ObjectName As String, Doc As Document) As Integer Select Case ObjectName Case "Sketch" Return Doc.ComponentDefinition.Sketches.Count Case "Sketch3D" Try Return Doc.ComponentDefinition.Sketches3D.Count Catch Return 0 'Sketch3DObject Doesn't exist for assemblies End Try End Select Logger.Debug(ObjectName & " not setup in Function: ""GetOtherObjectCount""") Return 0 End Function