How to get all unique part and sub assembly from main assembly in Solid Edge

Creator
Creator
I need count of all unique part and sub assembly of any Assembly file through VBA/VB.Net.

Ex. Let Suppose i have an assebly naming Assembly1. Assembly1 Contains both part file as well as sub Assembly file. Then,

Dim Count_Part As Integer = count of unique part file present in Assembly1
Dim Count_SubAssm As Integer = Count of all unique sub assembly file present in Assembly1
1 REPLY

Re: How to get all unique part and sub assembly from main assembly in Solid Edge

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

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