Page 1 of 1
Getting surface model vertex coordinates
Posted: Thu Jan 19, 2023 11:55 am
by edcoggins
Greetings. I am trying to get the 3D coordinates from a selection set of vertices in a surface model.
I found an example code in the API Help (create and delete selection sets) that returns the type of entity found in the selection set which is 3.
How can the 3D coordinates of the vertices be obtained?
Thanks in advance.
Re: Getting surface model vertex coordinates
Posted: Thu Jan 19, 2023 5:49 pm
by josh
set selected object = a Vertex object and use GetPoint
Re: Getting surface model vertex coordinates
Posted: Fri Jan 20, 2023 11:19 am
by edcoggins
Josh; Thanks for the tip!
Regards,
Ed
Re: Getting surface model vertex coordinates
Posted: Thu Apr 13, 2023 4:41 am
by mario malic
As mentioned above, it is possible to do it with a vertex object. It is an old thread, but posting for a complete solution. There are some extra unneccessarry objects since I used this macro for other purpose, but the vertex coords are found in
ptVar variant.
Code: Select all
Dim swApp As SldWorks.SldWorks
Sub main()
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim faceObj As SldWorks.Face2
Dim vertexObj As SldWorks.Vertex
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelExt = swModel.Extension
Set swSelMgr = swModel.SelectionManager
' Declare and initialise needed variables
Dim bool As Boolean
Dim numSelectedObjs As Integer
Dim selMark As Long
Dim selObjectType() As Long
Dim selObject() As Object
Dim ptCtr As Integer: ptCtr = 1
Dim ptObjArr As Variant
Dim ptVar() As Variant
Dim i, j As Integer
selMark = -1
' Check selection and reallocate needed objects
numSelectedObjs = swSelMgr.GetSelectedObjectCount2(selMark)
If (numSelectedObjs = 0) Then
MsgBox "No vertices selected"
End
End If
ReDim Preserve selObjectType(numSelectedObjs - 1)
ReDim Preserve selObject(numSelectedObjs - 1)
' Traverse selection and obtain vertex coordinates
For i = 1 To numSelectedObjs
selObjectType(i - 1) = swSelMgr.GetSelectedObjectType3(i, selMark)
If (selObjectType(i - 1) = SwConst.swSelVERTICES) Then 'Identify selection
Set vertexObj = swSelMgr.GetSelectedObject6(i, selMark)
Set selObject(i - 1) = vertexObj
ptObjArr = swSelMgr.GetSelectionPoint2(i, selMark)
ReDim Preserve ptVar(ptCtr - 1)
ptVar(ptCtr - 1) = ptObjArr
ptCtr = ptCtr + 1
'ElseIf (selObjectType(i - 1) = SwConst.swSelFACES) Then
'ElseIf (selObjectType(i - 1) = SwConst.swSelEDGES) Then
End If
Next
End Sub