Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
HideoYamada
in reply to: HideoYamada

Hello Keith,

 

I translated the VBA code into iLogic because I want to use .Net Collection Library.

 

Option Explicit On
Sub Main()
    Dim topAssyDoc As AssemblyDocument = ThisApplication.ActiveEditDocument
    Dim newPartDocuments As New System.Collections.Generic.List(Of PartDocument)
    CountNewParts(topAssyDoc.ComponentDefinition.Occurrences, newPartDocuments)
    MessageBox.Show("Count : " + newPartDocuments.Count.ToString())
    newPartDocuments.Clear()
End Sub

Sub CountNewParts(occs As ComponentOccurrences, newPartDocuments As System.Collections.Generic.List(Of PartDocument)) 
    Dim occ As ComponentOccurrence
    For Each occ In occs
        If IsNewPart(occ) Then
            Dim oPartDoc As PartDocument = occ.Definition.Document
            If Not newPartDocuments.Contains(oPartDoc) Then
                newPartDocuments.Add(oPartDoc)
            End If
'        ElseIf TypeOf occ.Definition Is AssemblyComponentDefinition Then
'            CountNewParts(occ.Definition.Occurrences, newPartDocuments)
        End If
    Next occ
End Sub

Function IsNewPart(occ As ComponentOccurrence) As Boolean
    IsNewPart = False
    If Not TypeOf occ.Definition Is PartComponentDefinition Then
        Exit Function
    End If
    Dim oPartDoc As PartDocument = occ.Definition.Document
    Dim partNumber As String
    partNumber = oPartDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value
    If Left(partNumber, 5) = "12345" Then
        IsNewPart = True
    End If
End Function

This code reports the number of new part documents (not occurrences of new part documents).

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp