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
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.
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
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'' Create 3D Points
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)
'' Select Points
'' 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)
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.
You're welcome and keep up the good work!
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?
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
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.