12-09-2015 11:51 AM
Solved! Go to Solution.
12-14-2015 04:51 AM
If you only need to get all unique parts and subassemblies from one the toplevel of an assembly, you can use the following code.
If you need to get all unique parts/subassemblies in the entire assembly, then you will need to recursively parse all occurrences and suboccurrences on all levels of the assembly. For that, you can start with the same code below.
'---------------------------------------------------------------------- ' ASM: Dump all unique part/subasms in a toplevel assembly '---------------------------------------------------------------------- Dim objDoc As AssemblyDocument = objApp.ActiveDocument Dim occsMap As New Collections.Generic.Dictionary(Of String, Integer) Dim strOccFileName As String For Each objOcc As Occurrence In objDoc.Occurrences strOccFileName = objOcc.OccurrenceFileName If occsMap.ContainsKey(strOccFileName) Then occsMap(strOccFileName) += 1 Else occsMap.Add(strOccFileName, 1) End If Next Debug.WriteLine("----- Unique Parts: ------") For Each kvp As KeyValuePair(Of String, Integer) In occsMap If Not kvp.Key.EndsWith(".asm", True, Globalization.CultureInfo.InvariantCulture) Then Debug.WriteLine(" " & kvp.Key & vbTab & vbTab & kvp.Value) End If Next Debug.WriteLine("----- Unique Subassemblies: ------") For Each kvp As KeyValuePair(Of String, Integer) In occsMap If kvp.Key.EndsWith(".asm", True, Globalization.CultureInfo.InvariantCulture) Then Debug.WriteLine(" " & kvp.Key & vbTab & vbTab & kvp.Value) End If Next