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.
<p>Sub main()</p><p>Dim swApp As SldWorks.SldWorks</p><p>Dim Part As ModelDoc2</p><p>Dim SelMgr As SldWorks.SelectionMgr</p><p></p><p>Set swApp = Application.SldWorks</p><p>Set Part = swApp.ActiveDoc</p><p>Set SelMgr = Part.SelectionManager</p><p> </p><p>Dim point As Variant</p><p>point = SelMgr.GetSelectionPoint2(1, -1)</p><p></p><p>Debug.Print point(0) 'X</p><p>Debug.Print point(1) 'Y</p><p>Debug.Print point(2) 'Z</p><p></p><p>End Sub</p>
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!
SolidworksApi macros
It's ok i found here:
2014 SOLIDWORKS API Help - Transform Coordinates from Sketch to Model Space Example (VBA)
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. . 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.
Thanks.It helps a lot.