2 Replies Latest reply on Nov 19, 2015 4:21 AM by Alexandre Gragnano

    Get Body instances of assembly document

    Alexandre Gragnano

      Hi everyone,

       

      I am trying to:

      - Traverse feature tree of assembly document (supposed fully resolved)

      - Find part components and analyse part document once if multiple instance

      - Get body instance of the part and all corresponding bodies if multiple instance

       

      Example:

      - Assembly document

         - Part1 component <1>

             - Body1

             - Body2

             - Body3

         - Part2 component

             - Body4

             - Body5

         - Part1 component <2>

             - Body1

             - Body2

             - Body3

       

      I need to get instances of Body2 in Part1 component <1> and Part1 component <2>.

       

      How can I perform this last point?

       

      Best regards,

      Alexandre

        • Re: Get Body instances of assembly document
          Amen Allah Jlili

          I'm not really sure I understood you but I hope this answers helps.

           

          1. Use GetComponents Method (IAssemblyDoc). Ideally the variable to which you assign the return of this method should be a variant.

          2. Define a Component2 variable and traverse the variant and from its lbound (lower bound) to its ubound (upper bound) assigning the traversed element to the Component2 variable on every iteration. Add an if condition (for the next step) that checks if Component2:Name2 contains "<1>". This condition will make sure you only get first instances of Component2.

          3. Use Component2::GetBodies3 to get the bodies. Ideally the variable to which you assign the return of this method should be a variant.

          4. I would suggest creating a custom class: A strongly typed collection of body and its corresponding components2. Add bodies to this collection as you traverse the bodies variant.


          It would helpful if you can explain further what you want to do with bodies to get a concise answer.

           

          Best,

          JLILI Amen

            • Re: Get Body instances of assembly document
              Alexandre Gragnano

              Thank you for your help,

               

              I am developing a C# SolidWorks task pane addin which flattens this sort of anarchical feature manager tree view:

               

              - Assembly

                 - Part1

                     - CutList1

                     - CutList2

                 - SubAssembly

                     - Part1

                         - CutList1

                         - CutList2

                     - Part2

                         - CutListA

                         - CutListB

                 - Folder

                     - Part2

                         - CutListA

                         - CutListB

                 - Part2

                     - CutListA

                     - CutListB

               

              to a custom tree view:

               

              - Assembly

                 - Part1 (2 components)

                     - CutList1 (3 bodies)

                     - CutList2 (1 body)

                 - Part2 (3 components)

                     - CutListA (2 bodies)

                     - CutListB (5 bodies)

               

              Note: Assembly is supposed fully resolved and SubAssembly(ies)/Folder(s) become invisible.

              This tool is a custom bill of material manager with specific functions.

               

              My objective is to:

                  - Select all CutList1 bodies of all Part1 components in the Assembly context if I click on CutList1 tree view item.

               

               

              What I need to understand is:

              - Is two distinct components sibling a same document have a GetModelDoc2 method returning a same object reference?

              - If GetModelDoc2 method returns same reference, Body2 references of two distinct components will be the same?

              - Is two corresponding bodies of two distinct components sibling a same document have a same Id/Persistent Id?

              - What are the different members of corresponding objects of two distinct components sibling a same document?

              - There is a way to reference them simply?

               

              Best regards,

              Alexandre