11-04-2019
06:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-04-2019
06:20 PM
Hello,
Try this code (VBA).
The code counts the Parts which part number is started with "12345".
Option Explicit
'
' This Code is written in VBA.
'
Sub Main()
Dim topAssyDoc As AssemblyDocument
Set topAssyDoc = ThisApplication.ActiveEditDocument
Dim count As Integer
count = CountNewParts(topAssyDoc.ComponentDefinition.Occurrences)
MsgBox "Count : " & count
End Sub
Function CountNewParts(occs As ComponentOccurrences) As Integer
CountNewParts = 0
Dim occ As ComponentOccurrence
For Each occ In occs
If IsNewPart(occ) Then
CountNewParts = CountNewParts + 1
ElseIf TypeOf occ.Definition Is AssemblyComponentDefinition Then
CountNewParts = CountNewParts + CountNewParts(occ.Definition.Occurrences)
End If
Next occ
End Function
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
Set oPartDoc = 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=====
Hideo Yamada