3 Replies Latest reply on Mar 10, 2015 11:44 PM by Kasun Udayanga

# Get coordinates point in a sketch (Problem negativ/positiv value)

Hi everyone

I use this code to get the point coordinates where i just clicked with my mouse:

Its working if i select a sketch point, and also if i click on 3D Model surface.

Sub main()

Dim swApp As SldWorks.SldWorks

Dim Part As ModelDoc2

Dim SelMgr As SldWorks.SelectionMgr

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

Set SelMgr = Part.SelectionManager

Dim point As Variant

point = SelMgr.GetSelectionPoint2(1, -1)

Debug.Print point(0) 'X

Debug.Print point(1) 'Y

Debug.Print point(2) 'Z

End Sub

I don't know why, sometime, when i'm editing a sketch, the coordinate axes can be reversed:

As you can see in this example, the 'X' axe of the sketch is in a reverse sens of the 'X' axe of the 3D model.

So if i click on a sketch point, i have the sketch coordinates.

And if i click on the surface of the Model, i got the 3D model coordinate  ...:  the negative of the X sketch coordinates, even if its in the same location.

Then if i want to insert a block in the sketch, by the way of clicking on the Model surface,

the block will appear in the symetrie of 'Y' axe, because  X = - X.

Can you have a solution to coordonate (haha) the landmark?

Maybe a different code or a VBA trick?

Thank you very much!

• ###### Re: Get coordinates point in a sketch (Problem negativ/positiv value)

Ironically, I was having this same problem a couple of days ago. I used the same example you did. Here is a breakdown of some of the things that tripped me up. Trouble getting true (model) coordinates of sketch point . One important thing I found out, if you are using API to make your selection, the coordinates need to be fed to the IMathUtility::CreatePoint command with an array of type double. The transform was coming back incorrect when I didn't unless I was physically selecting the point.

• ###### Re: Get coordinates point in a sketch (Problem negativ/positiv value)

Thanks.It helps a lot.