I've learned some things and refined my question;
I select a Component in a lower level assembly in a Drawing view. The name of that component reports as:
Getting the Component2 and subsequent ModelDoc for this object returns the 45000-6172-001 (the actual part object selected - makes sense).
I want to however get the ModelDoc for the 45000-3086-001-1... How can I do this? Chasing the Component.GetParent up the hierarchy doesn't work.
GetParent works until the top-level view reference. Try the following to get the entire reference structure...
Dim model As ModelDoc2 = swApp.ActiveDoc
Dim draw As DrawingDoc = model
Dim sm As SelectionMgr = model.SelectionManager
If sm.GetSelectedObjectCount2(-1) <> 2 Then Exit Sub
Dim v As View = sm.GetSelectedObject6(1, -1) 'first item is view, second is selected component
Dim comp As DrawingComponent = sm.GetSelectedObjectsComponent4(2, -1)
Debug.Print("Selection: " & comp.Name)
Dim topcomp As DrawingComponent = v.RootDrawingComponent()
Dim parentComp As Component2 = comp.Component.GetParent
Do While Not IsNothing(parentComp)
Debug.Print(" Parent: " & parentComp.Name2)
parentComp = parentComp.GetParent
Debug.Print(" Top Parent: " & topcomp.Name)
Stop 'review Immediate Window
I've found a fundamental issue with this that I'll try to mock-up in a simple example so I can communicate it accurately.
Basically the .GetParent of the associated Component2 object only works up one level. I need to go up many levels. It appears as though the Parent Component represents the entire hierarchy from the Top Level to the Component (as evidenced by the .Name property xxx/xxx/xxx/xxx, and doing a GetParent on this objects returns Nothing.)...
I'll try your code exactly in my app and report back. Thank you for your reply.
Well, this worked. Not sure what I was doing wrong... and I've since taken a different approach so I can't check.
Always good to learn . I wasn't aware the 1st item was the View, and this helps with another challenge.
Thank you for the education.
Top Parent: 45000-3075-001-1
Glad it worked for you!