Showing results for 
Search instead for 
Did you mean: 

How to get the current assembly occurrence parent occurrence?


Hi all!

    I get the occerecce through mouse in current ASM. I want to obtain the  parent object. This object's type must be Occerence. My ASM  is a multi-level.



Dependend on the current assembly level, the Item in the...

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Dependend on the current assembly level, the Item in the selectset is either a reference or an occurrence. Selected items on the toplevel are returned as occurrences, while objects in a deeper level are returned as references.
The parent of an occurrence is the active toplevel assembly and for the reference you can get the ImmediateParent, which itself can be again either a Reference or an Occurrence.
The following code should show you the direct parent of the selected (sub)occurrence:

' ASM: Show the immediate parent of the selected (sub)occurrence
Dim objSelSet As SolidEdgeFramework.SelectSet = objApp.ActiveSelectSet
If objSelSet.Count = 1 Then
  Dim objSelItem As Object = objSelSet.Item(1)
  Dim selItemType As Integer = objSelItem.GetType().InvokeMember("Type", Reflection.BindingFlags.GetProperty, Nothing, objSelItem, Nothing)
  Dim strParentName As String = ""
  If selItemType = SolidEdgeConstants.ObjectType.igReference Then
    ' Selected item is a suboccurrence in a subassembly
    Dim objSelRef As SolidEdgeFramework.Reference = objSelItem
    Dim parentType As Integer = objSelRef.ImmediateParent.GetType().InvokeMember("Type", Reflection.BindingFlags.GetProperty, Nothing, objSelRef.ImmediateParent, Nothing)
    Dim objParent As SolidEdgeAssembly.Occurrence = Nothing
    If parentType = SolidEdgeConstants.ObjectType.igReference Then
      Dim objParentRef As SolidEdgeFramework.Reference = objSelRef.ImmediateParent
      objParent = objParentRef.Object
    ElseIf parentType = SolidEdgeConstants.ObjectType.igSubAssembly Then
      objParent = objSelRef.ImmediateParent
    End If
    strParentName = objParent.Name
  ElseIf selItemType = SolidEdgeConstants.ObjectType.igPart OrElse selItemType = SolidEdgeConstants.ObjectType.igSubAssembly Then
    ' Selected item is an occurrence of the toplevel assembly
    Dim objSelOcc As SolidEdgeAssembly.Occurrence = DirectCast(objSelItem, SolidEdgeAssembly.Occurrence)
    strParentName = objSelOcc.TopLevelDocument.Name
    strParentName = "<unknown_parent>"
  End If
  MessageBox.Show("Parent: " & strParentName)
End If