How do I get the part to which the selected segment belongs in drawing?

In drawing,I have selected one segment and I want to  know that how to get which part it belongs to?

 Please look at the information selected below in the diagram .

I am fluent in VB.

Thank you for all your help!

SolidworksApi/macros
Comments 5
CZ
CZ 2021-04-08

Hi,

You're a genius,and thank you .

The problem was solved

AT
AT 2021-04-08

You are correct, Josh. I overlooked this.

JB
JB 2021-04-08

Artem Taturevych wrote:

ISelectionMgr::GetSelectedObjectsDrawingView2->IView::ReferencedDocument

Unless I miss my guess, this is an assembly drawing, and he wants the document for the component owning the edge selected.

One thing to recognize... when you select an edge/face in a drawing view, it's not actually the only selected object. The view is selected also.

See this snippet:

If Part.GetType = swDocDRAWING Then
  If SelMgr.GetSelectedObjectType2(1) = swSelDRAWINGVIEWS Then
    Set myView = SelMgr.GetSelectedObject5(1)
    Set modRefByView = myView.ReferencedDocument
    If modRefByView.GetType = swDocPART Then
      Set Part2Open = swApp.ActivateDoc2(modRefByView.GetPathName, False, dummy)
    ElseIf modRefByView.GetType = swDocASSEMBLY Then
      If SelMgr.GetSelectedObjectCount = 2 Then
        Set MyDwgComp = SelMgr.GetSelectedObjectsComponent2(2)
        Set MyComp = MyDwgComp.Component
        Set Part2Open = swApp.ActivateDoc2(MyComp.GetPathName, False, dummy)
      End If
    End If
  ElseIf SelMgr.GetSelectedObjectType3(1, -1) = swSelCOMPONENTS Then
    Set MyDwgComp = SelMgr.GetSelectedObject6(1, -1)
    Set MyComp = MyDwgComp.Component
    Set Part2Open = swApp.ActivateDoc2(MyComp.GetPathName, False, dummy)
  End If
Else

AT
AT 2021-04-08

ISelectionMgr::GetSelectedObjectsDrawingView2->IView::ReferencedDocument

KS
KS 2021-04-08

Click RMB and choice Open Part

EDIT.

SOOORY... I'm stupid, did not notice that the question concerns the API.