7 Replies Latest reply on Mar 20, 2014 3:40 AM by Blandine Ganivet

    Insert Ref plane

    Blandine Ganivet

      I would like to insert a reference plane using 3 3D points.

      Here is my code and I don't know why it doesn't work. pleeeaaaase can you help me?


      public void DrawSurface()


                  RefPlane myRefPlane = default(RefPlane);

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



                  SketchPoint SkPoint1 = ((SketchPoint)(swDoc.SketchManager.CreatePoint(2,3,4)));

                  SketchPoint SkPoint2 = ((SketchPoint)(swDoc.SketchManager.CreatePoint(4,1,2)));

                  SketchPoint SkPoint3 = ((SketchPoint)(swDoc.SketchManager.CreatePoint(l1,1,1)));


                  bool boolstatus;

                  boolstatus = swDoc.Extension.SelectByID2("Point1@Esquisse3D1", "EXTSKETCHPOINT", 2,3,4, true, 0, null, 0);

                  boolstatus = swDoc.Extension.SelectByID2("Point2@Esquisse3D1", "EXTSKETCHPOINT", 4,1,2, true, 1, null, 0);

                  boolstatus = swDoc.Extension.SelectByID2("Point3@Esquisse3D1", "EXTSKETCHPOINT", 1,1,1, true, 2, null, 0);

                  myRefPlane = ((RefPlane)(swDoc.FeatureManager.InsertRefPlane(4, 0, 4, 0, 4, 0)));


        • Re: Insert Ref plane
          Artem Taturevych

          Try avoid using the SelectById2 for selection. In this particular case I think that your points out of the space so cannot be selected. I would recommend using direct selection methods




          You can also take a look at this method: ModelDoc2::CreatePlaneFixed2 which creates a reference plane by 3 points without a need of creating those points. This method is marked as obsolete but I think it is not obsolete.


          Regards, Artem Taturevych | Snr. Developer | IC3D ANZ


          IC3DSteel – New Steel Solution for SolidWorks

          translationXpert – SolidWorks files language translator

          LinkedIn - SolidWorks API Group

          • Re: Insert Ref plane
            Gustavo Oliveira

            Try this code in VBA, unfortunately I can not use C++ at the moment, but you can easily convert.


            Let me know if it helped.


            Good luck


            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

            Dim skPoint1 As SldWorks.SketchPoint

            Dim skPoint2 As SldWorks.SketchPoint

            Dim skPoint3 As SldWorks.SketchPoint

            Dim swRefPlane As SldWorks.RefPlane

            Dim boolstatus As Boolean


            Sub main()


                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc


                '' Create 3D Points

                swModel.SketchManager.Insert3DSketch True

                Set skPoint1 = swModel.SketchManager.CreatePoint(0.002, 0.003, 0.004)

                Set skPoint2 = swModel.SketchManager.CreatePoint(0.004, 0.001, 0.002)

                Set skPoint3 = swModel.SketchManager.CreatePoint(0.001, 0.001, 0.001)

                swModel.ClearSelection2 True

                swModel.SketchManager.Insert3DSketch True


                '' Select Points

                swModel.ClearSelection2 True

                '' I prefer this way to select

                boolstatus = skPoint1.Select2(True, 0)

                boolstatus = skPoint2.Select2(True, 1)

                boolstatus = skPoint3.Select2(True, 2)

                '' but you can also use this way if you prefer

                'boolstatus = swModel.Extension.SelectByID2("", "EXTSKETCHPOINT", 0.002, 0.003, 0.004, True, 0, Nothing, 0)

                'boolstatus = swModel.Extension.SelectByID2("", "EXTSKETCHPOINT", 0.004, 0.001, 0.002, True, 1, Nothing, 0)

                'boolstatus = swModel.Extension.SelectByID2("", "EXTSKETCHPOINT", 0.001, 0.001, 0.001, True, 2, Nothing, 0)


                '' Create RefPlane

                Set swRefPlane = swModel.FeatureManager.InsertRefPlane(4, 0, 4, 0, 4, 0)

                swModel.ClearSelection2 True


            End Sub

              • Re: Insert Ref plane
                Blandine Ganivet

                Thank you for your answer.

                Gustavo Oliveira, I try your way to select the points and now it works!!

                Artem Taturevych, I will try with CreatePlaneFixed2 to make it directly.


                  • Re: Insert Ref plane
                    Gustavo Oliveira

                    You're welcome and keep up the good work!

                      • Re: Insert Ref plane
                        Blandine Ganivet

                        I just have a last question How can I get the coordinates of my three points skPoint1, skPoint2, skPoint3 in the plane?

                        Becuse I have to select this point to draw a parallelogram. Do you have any ideas?

                          • Re: Insert Ref plane
                            Gustavo Oliveira

                            You can just use the public properties of the sketchpoint object.

                            Is this what you want to do?

                            Let me know if it helped.

                                Dim x1 As Double
                                Dim y1 As Double
                                Dim z1 As Double
                                Dim x2 As Double
                                Dim y2 As Double
                                Dim z2 As Double
                                Dim x3 As Double
                                Dim y3 As Double
                                Dim z3 As Double
                                '' Point1 Coords
                                x1 = skPoint1.X
                                y1 = skPoint1.Y
                                z1 = skPoint1.Z
                                '' Point2 Coords
                                x2 = skPoint2.X
                                y2 = skPoint2.Y
                                z2 = skPoint2.Z
                                '' Point3 Coords
                                x3 = skPoint3.X
                                y3 = skPoint3.Y
                                z3 = skPoint3.Z

                              • Re: Insert Ref plane
                                Blandine Ganivet

                                What I want to do is a little bit complicated....

                                I want to create a plane with 3 points in 3D. Then I want to do the coordinates of those points but on ths own coordinate system of the plane, of the 2D sketch because I want to draw a parallelogram with those points.

                                I don't know if I am very clear...

                                I want use again the same point but in a 2D sketch.