5 Replies Latest reply on Feb 13, 2016 4:56 PM by Michael Spens

    Recursing UP an Assembly from a Drawing Component

    John Howell

      Hello all.

       

      Within the context of a VB.NET AddIn, I'm trying to find the upper level owning assembly via a Drawing Component. This is for a custom Item Bubbler I'm building (due to the nature of our data, we can not use SolidWorks BOM functionality).

       

      For example, a user may click a part way down the tree when inserting an Item Bubble. What I want to do is get the owning assembly of that component, possibly up several levels, that is one under the child of the drawing - e.g., the Item that would be on that BOM.

       

      I first get the DrawingComponent the user selected, then the model Component of that DrawingComponent via DrawingComponent.Component. Easy enough.

       

      I then get the Parent Component of that model Component via Component.GetParent. Easy enough.

       

      Where I run into problems is getting the Parent of that Parent Component - it always comes back empty, even though there are several layers to the upper level assembly.

       

      Is there a fundamental issue using .GetParent to traverse UP an Assembly? Possibly an issue due to the fact I'm in a drawing and starting with the Drawing Component?

       

      Any other ideas and/or a different approach?

       

      Thank you for any help.

        • Re: Recursing UP an Assembly from a Drawing Component
          John Howell

          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:

           

          45000-3075-001-1/45000-3086-001-1/45000-6223-001-1/45000-6172-001-1

           

          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.

            • Re: Recursing UP an Assembly from a Drawing Component
              Michael Spens

              Hi John,

              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

                      Loop

                      Debug.Print("    Top Parent: " & topcomp.Name)

               

                      Stop 'review Immediate Window