Extract the coordinates of a point

Hi all

Please, I'm looking for how to determine the coordinates of a point  of a part in solidworks using VB.NET.

Thank you in advance.


oo.png

Hello

I don't know how to do it but it's displayed at the bottom of the screen if you click on it. A click like launching the macro.


coordonnees_dun_point.jpg
2 Likes

Hello

Can you specify the goal please? do you want to take the X, Y and Z values of the point in question or do you want to position this point in X, Y and Z?

Kind regards

1 Like

Good evening and thank you for your answers, I am trying to determine the X, Y and Z values of a point in a SW room using VB.NET.

Hello, but anyway you will select the desired point!? And you would like to export his coordinates in an excel that's it????

Kind regards

Hello

This macro allows you to display the X, Y, and Z coordinates of a selected point.

Dim swApp As SldWorks.SldWorks
Sub main()

Set swApp = Application.SldWorks
Dim swModel As ModelDoc2
Set swModel = swApp.ActiveDoc
Dim mgr As SelectionMgr
Set mgr = swModel.SelectionManager
Dim Coordinates() As Double
Coordinates = mgr.GetSelectionPoint2(1, 0)
MsgBox (Coordinates(0) * 1000 & "," & Coordinates(1) * 1000 & "," & Coordinates(2) * 1000)
End Sub

 

The selected coordinates are in meters, I multiplied by 1000 to display them in mm.

3 Likes

Hello, yes it's almost this macro, but I'm looking to select the point to be determined with the vb.net too.

  I tried to put

boolstatus = swDocExt.SelectByID2("nom_du_point@nom_de_la_piece@nom_d_assemblage", "EXTSKETCHPOINT", 0, 0, 0, True, 1, Nothing, 0)

before 

Dim Coordinates() As Double

But, I got this answer:

The object reference is not set to an instance of an object.

 

 

Hello

Try the following:

Dim swApp As SldWorks.SldWorks

Sub main()
    Set swApp = Application.SldWorks
    Dim Part As ModelDoc2
    Set Part = swApp.ActiveDoc
    Dim swSelMgr As SelectionMgr
    Set swSelMgr = Part.SelectionManager
    boolstatus = Part.Extension.SelectByID2("Point1@Esquisse3D1", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
    Dim skPoint As SketchPoint
    Set skPoint = swSelMgr.GetSelectedObject6(1, -1)
    MsgBox (skPoint.X * 1000 & " - " & skPoint.Y * 1000 & " - " & skPoint.Z * 1000)
End Sub

by replacing "Point1@Esquisse3D1" with the name of your point ("nom_du_point@nom_de_la_piece@nom_d_assemblage").

Kind regards

3 Likes

Thank you very much for your help.