- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
top level assm. would be 12345000
new parts would be 12345001 to 12345009
new sub assm. would be 12345010
reused parts would be 11111001 to 11111009
reused assm. would be 11111010
i need to get a total number of new parts with total weight from the model.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
no longer need weight just a count of new parts. here's what i have so far. it seems to miss all the part numbers
Sub Main() ' Get the active assembly. Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument ' Get the assembly component definition. Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition.iProperties.Value("Project", "Part Number") oNum = oAsmDef.iProperties.Value("Project", "Part Number",Left(12345000,5)) ' Get all of the leaf occurrences of the assembly. Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences ' Iterate through the occurrences and print the name. Dim cnt As Integer cnt = 0 Dim oOcc As ComponentOccurrence oOcc = oLeafOccs(iProperties.Value("Project", "Part Number",Left(12345000,5))) For Each oOcc In oLeafOccs If oLeafOccs = oNum Then cnt = cnt + 1 MessageBox.Show(oOcc.Name) End If Next MessageBox.Show(cnt) End Sub
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
that does count everything. is there a way to automatically extract the first 5 digits of the top level assembly for the search string? also i only need to count .ipt files that start with the first 5 digits of the top level assembly. this counts subassemblies as parts too. thanks for helping me with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
@Anonymous wrote:that does count everything. is there a way to automatically extract the first 5 digits of the top level assembly for the search string? also i only need to count .ipt files that start with the first 5 digits of the top level assembly. this counts subassemblies as parts too. thanks for helping me with this.
Delete or comment out these two lines :
' ElseIf TypeOf occ.Definition Is AssemblyComponentDefinition Then ' CountNewParts = CountNewParts + CountNewParts(occ.Definition.Occurrences)
=====
Hideo Yamada
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous wrote:also i only need number of new part numbers created not number of new part occurrences. thanks for your help
Ah, this needs a bit complex code. Just wait...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 FunctionThis code reports the number of new part documents (not occurrences of new part documents).
=====
Hideo Yamada
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i made a little mod but your code works great. thanks for your help
Sub Main()
Dim topAssyDoc As AssemblyDocument = ThisApplication.ActiveEditDocument
Dim newPartDocuments As New System.Collections.Generic.List(Of PartDocument)
Dim sSN As String
sSN = InputBox("Please enter first five digits of parts you are interested in:", "Input needed", "xxxxx")
CountNewParts(topAssyDoc.ComponentDefinition.Occurrences, newPartDocuments, sSN)
MessageBox.Show("Count : " + newPartDocuments.Count.ToString())
newPartDocuments.Clear()
End Sub
Sub CountNewParts(occs As ComponentOccurrences, newPartDocuments As System.Collections.Generic.List(Of PartDocument), sSN As String)
Dim occ As ComponentOccurrence
For Each occ In occs
If IsNewPart(occ, sSN) 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,sSN)
End If
Next occ
End Sub