8 Replies Latest reply on Jan 10, 2013 5:47 AM by Shane Wong

    Add components to assembly

    Shane Wong

      hi, there,

       

      I use AssemblyDoc.AddComponent5 to add a component into an assembly. But I found an interesting problem and don't know why this happens.

       

      component = assDoc.AddComponent5(path, swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", x, y, z)

       

      I want to place the component at origin (x=0, y=0, z=0), but the first running the program I will always get a false place of (x, y, z), while the second time is correct. (see pic1&2)

      I didn't do anything between these two runnings, however I get totally different results, really don't know why. Could someone explain it a little bit??

       

      regards,

      Shane

        • Re: Add components to assembly
          Keith Rice

          Shane,

           

          Do you get the same result if you use IAssemblyDoc::AddComponent4? (I tend to use that one anyway, since its simpler to use.)

           

          Keith

          Video Tutorials for the SolidWorks API

            • Re: Add components to assembly
              Shane Wong

              hi Keith,

               

              Yes, I also tried AddComponent4, but it's the same.

               

              What confuse me most is that I tracked each value of (x, y, z) in the program, even after AddComponent5/4 has been executed, their values are still right. However, when the component is added into the assembly, the place of the component (center) is wrong anyway. And it's wrong only when the component is first added.

               

              Actually I found no matter what value of y is set manually (by me), the program will always get a constant value (-5). I checked my program and found no relation with this value. This is really tricky...

            • Re: Add components to assembly
              Artem Taturevych

              Try AssemblyDoc::AddComponents3 with Nothing for transforms to place the component in {0,0,0}

              __________________________

              Regards,

              Artem Taturevych

              Application Engineer at Intercad

              http://intercad.com.au/

              Tel: +61 2 9454 4444

                • Re: Add components to assembly
                  Shane Wong

                  hi, Artem,

                   

                  I tried AddComponent3, but turned out I used it wrongly, sldwrks throws me an error

                   

                  Because I will add many components into the assembly and I need to place them in the right place before adding mate, therefore I chose AddComponent5. It can directly control the position of component. Seems like AddComponent3 might also do this through controling Transform2? I tried, but it failed.

                    • Re: Add components to assembly
                      Artem Taturevych

                      Hi Shane,

                       

                      There are three advantages of this method comparing to regular AddComponentX:

                       

                      1) No need to open the component files before inserting to the assembly.

                      2) Possibility to add several component as a batch increasing the performance

                      3) Possibility to specify the transforms/coordinate system which allows to use rotation in addition to translation.

                       

                      I think this method should be useful for you.

                       

                      Have you tried the sample listed in API Help under the description of this method? What exactly the exception do you have? Can you provide code snippet you are using?

                      __________________________

                      Regards,

                      Artem Taturevych

                      Application Engineer at Intercad

                      http://intercad.com.au/

                      Tel: +61 2 9454 4444

                        • Re: Add components to assembly
                          Shane Wong

                          Hi, Artem,

                           

                          I tried AddComponent3, still have some problems cann't understand.

                           

                          1. how to control the position of the component when added into assembly? is it through the translation vector in componentXforms? If so, there must be a reference point or system in the assembly and component simultaneously.

                           

                          2. what is the coordinate system in component used for? does it means that the transformation of the component is carried out through this coordinate system? Is my understanding right?

                           

                          for example, right now i want to add component into assembly with translation (x=10, y=10, z=10) but no rotation. What should the translation vector and scaling factor be?

                           

                          I found relatied information under this method (AddComponent3) and MathTransform, but it's not thorough enough. Is there any more information or example using this method for me to learn? 

                           

                          regards,

                          Shane

                            • Re: Add components to assembly
                              Artem Taturevych

                              Hi Shane,

                               

                              how to control the position of the component when added into assembly? is it through the translation vector in componentXforms? If so, there must be a reference point or system in the assembly and component simultaneously.

                               

                              Yes, you are right. The reference point (coordinate system) is the assembly global coordinate system.

                               

                              what is the coordinate system in component used for? does it means that the transformation of the component is carried out through this coordinate system? Is my understanding right?

                               

                              You can specify the name(s) of component's coordinate systems and this will be aligned with assembly global coordinate system.

                               

                              for example, right now i want to add component into assembly with translation (x=10, y=10, z=10) but no rotation. What should the translation vector and scaling factor be?

                               

                              I found relatied information under this method (AddComponent3) and MathTransform, but it's not thorough enough. Is there any more information or example using this method for me to learn?

                              I have created a sample (VB.NET VSTA macro) which shows how this method could be used. I shown how you can add multiple components as a batch specifying the insertion points. You may change the number of insertion components. Note the number of components should be equal to the number of points. This will add these components and automatically position. Note - no need to open these files explicitly.

                               

                              Please let me know if you have any questions.

                              __________________________

                              Regards,

                              Artem Taturevych

                              Application Engineer at Intercad

                              http://intercad.com.au/

                              Tel: +61 2 9454 4444