6 Replies Latest reply on Apr 6, 2015 10:42 AM by Keith Rice

    Have problem with GetIntersectionEdges method.

    Fivezdw Fivezdw

      I have a program which needs implementing GetIntersectionEdges method.

      I used GetIntersectionEdges method to check whether two temporary bodies intersect with each other.

      However, I realized that when two bodies are touching but not really intersecting, there will also be intersecting edges between the two bodies.

      And the returned array will also be non-empty for two bodies touching but not intersecting.

      I'm only interested in the situation where two temp bodies are really intersecting.

      I was wondering how I can tell from the returned array of intersecting edges whether two temporary bodies are just touching or actually intersecting.

      Can anybody help me with this question. Would really appreciate your help.

        • Re: Have problem with GetIntersectionEdges method.
          Keith Rice

          You could run IBody2::Operations2 on the two bodies using the combine option. If no body is returned, then they were only touching. Even if a body is returned, you could examine the physical properties of that body using IBody2::GetMassProperties. If the volume is very close to 0, then you could regard the two original bodies as only touching.

           

          Keith

          SolidWorks API Training

            • Re: Have problem with GetIntersectionEdges method.
              Fivezdw Fivezdw

              Hi, Keith

              Did you mean the IBody2::Operations2 SWBODYADD operation ?

              I have tried the Operations2 method. However, I'm not sure how to put the three parameters when using C#.

              The examples in SolidWorks API help are all in VBA.

              I used the following expression, but it turned out to be an error. (Have some invalid arguments)

               

               

               

               

               

               

               

               

               

              IBody2 tempBody = default(IBody2);

              IBody2 tempBodyTool = default(IBody2);

               

              tempBody.Operations2 ((int)swBodyOperationType_e.SWBODYADD, (IBody2)tempBodyTool, (int)swBodyOperationError_e.swBodyOperationNoIntersect);

               

              it seems the problem comes from the first parameter (i.e. OperatioinType). I believe the first parameter should have an int type. But, SolidWorks API help, there are no indication of integer assignment for each operation type.

               

              Hence, can you help with it?

                • Re: Have problem with GetIntersectionEdges method.
                  Keith Rice

                  The integers you can use for the first argument are found in the first API Help example.

                   

                  Public Const SWBODYINTERSECT    As Integer = 15901

                  Public Const SWBODYCUT          As Integer = 15902

                  Public Const SWBODYADD          As Integer = 15903

                   

                  They are also found in swBodyOperationType_e. Hence I would write the code like this:

                   

                  using SolidWorks.Interop.sldworks;
                  using SolidWorks.Interop.swconst;
                  using System.Runtime.InteropServices;
                  using System;
                  using System.Windows.Forms;
                  
                  namespace operations2.csproj
                  {
                      public partial class SolidWorksMacro
                      {
                  
                          public void Main()
                          {
                              ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;
                              SelectionMgr swSelMgr = (SelectionMgr)swModel.SelectionManager;
                              Body2 mainBody = (Body2)swSelMgr.GetSelectedObject6(1, -1);
                              Body2 toolBody = (Body2)swSelMgr.GetSelectedObject6(2, -1);
                  
                              mainBody = (Body2)mainBody.Copy();
                              toolBody = (Body2)toolBody.Copy();
                  
                              int err = 0;
                              object retBodies = (object)mainBody.Operations2((int)swBodyOperationType_e.SWBODYINTERSECT, 
                                  toolBody, out err);
                  
                              if (err != 0)
                                  MessageBox.Show("Error during operation: " + err.ToString());
                              else
                              {
                                  if (retBodies == null)
                                      MessageBox.Show("Bodies do not intersect");
                                  else
                                      MessageBox.Show("Bodies intersect");
                              }
                          }
                  
                          public SldWorks swApp;
                      }
                  }
                  

                   

                  If you get an error, you can learn about it by doing to swBodyOperationError_e in the API Help.

                   

                  Note that you need to have two bodies selected in the feature manager tree to run the above code.

                   

                  Keith

                  SolidWorks API Training

                • Re: Have problem with GetIntersectionEdges method.
                  Fivezdw Fivezdw

                  Hi, Keith

                   

                  Could you please take a look at my last respond to you.

                   

                  I have tried the Operations2 method but I don't know how to write it using C# language.

                   

                  I'm sorry to bother you but it's pretty urgent for me to finish the program.

                   

                  Hope you can give me some assistance.

                   

                  Thank you.

                  Dwu

                • Re: Have problem with GetIntersectionEdges method.
                  Jacob Corder

                  you should be able to use imodeler.