8 Replies Latest reply on Mar 20, 2016 1:00 PM by Marco Maso

    (C#) Intersection curve: crash when using Insert3DSketch

    Marco Maso

      Hi, I'm trying to get an intersection curve between a plane and a surface. Reading the API docs, I tried to use Insert3DSketch but everytime I try to use it Solidworks crashes without notice.

       

      I also tried to register a macro in order to see the commands. The macro works fine.

       

      I'm trying with this code:

       

      swDoc = ((ModelDoc2)(swApp.ActiveDoc));

      Body2 myBody = (Body2)bo;

      swSelectionManager.AddSelectionListObject(myReferencePlane, selData);

      swDoc.SketchManager.InsertSketch(true);

      swDoc.Sketch3DIntersections();

      swSelectionManager.AddSelectionListObject(myBody, selData);

      swDoc.Sketch3DIntersections();

      swDoc.ClearSelection2(true);

      swDoc.Sketch3DIntersections();

      swDoc.ClearSelection2(true);

      swDoc.SketchManager.InsertSketch(true);

       

      Thanks.

        • Re: (C#) SW crashes when using Insert3DSketch
          Marco Maso

          I tried to isolate the problem. Apparently the error is related to the Insert3DSketch function. I can enter into sketch mode, insert a sketch, but as soon as I try to use Insert3DSketch, Solidworks crashes.

           

          Any insight?

            • Re: (C#) Intersection curve: crash when using Insert3DSketch
              Artem Taturevych

              Please answer some questions below which may help to understand the problem?

               

              • Are you in Part or in Assembly?
              • Why do you call Sketch3DIntersection second time after clear selection (so no entities are selected required for this method)?
              • How to did you retrieve the pointers to bo and myReferencePlane?
                • Re: (C#) Intersection curve: crash when using Insert3DSketch
                  Marco Maso

                  Hi Artem, thanks for your reply.

                  • I'm in Part
                  • Sorry, it was a leftover from the macro I tried to imitate after several unsuccessful tries. Actually I call Sketch3DIntersection, ClearSelection2 and InsertSketch.
                  • bo is actually retrieved from an edge using Edge.GetBody(). myReferencePlane is a RefPlane I made using the very same edge as constraint. If I stop the execution before Insert3DSketch, I can see that they are correctly selected in SW.

                  That's very strange. I don't think that the problem is due to bo/myReferencePlan, simply calling Insert3DSketch, even before everything else, leads to a crash.

                  • Re: (C#) Intersection curve: crash when using Insert3DSketch
                    Marco Maso

                    Hi, any update on this? Thank you.

                      • Re: (C#) Intersection curve: crash when using Insert3DSketch
                        Artem Taturevych

                        Hi,

                         

                        Is your macro just does an intersection and no more actions? If so could you please attach this macro and the model? Otherwise

                        try to create a very simple macro which just does 3D intersection. Does it crashes? if not you need to look in your previous code and try to suppress the block to find what is causing it. I believe the problem is not a 3D Sketch inserting, even not 3D intersection but something which happened before.

                         

                        In most cases one of the following may cause such a behavior:

                         

                        • Incorrect use of temp bodies. For example some of the APIs are intended to be used for temp bodies while used on regular ones or vice-versa (for example Body2::Hide for temp body while Body2::HideBody for regular ones)
                        • Incorrect use of contexts (for example you are trying to insert a feature into a Part from assembly without putting the component into edit mode