API Question...
API Question...
(OP)
Hi All,
I need some help with code for selecting/querying points in sketches which exist in SolidWorks parts that are being added to an assembly. If anyone show me how I might query such points in order to obtain their location information in relation to the origin of the assembly it would be much appreciated.
Thanks,
RHR
I need some help with code for selecting/querying points in sketches which exist in SolidWorks parts that are being added to an assembly. If anyone show me how I might query such points in order to obtain their location information in relation to the origin of the assembly it would be much appreciated.
Thanks,
RHR






RE: API Question...
Here it is with a little more added:
CODE
'Get Sketch Points Example (VB)
'This example shows how to loop through the active sketch and extract the X,Y values of every sketch point.
'-----------------------------------------------
'
' Preconditions:
' (1) Document is open.
' (2) Editing a Sketch.
'
' Postconditions: None
'
'-----------------------------------------------
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim sketchPointArray As Variant
' Optional
Dim theSketchPoint As Object
Dim pointCount As Integer
Dim xValue As Double
Dim yValue As Double
Dim zValue As Double
Dim ExtraSpace As String
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set theSketch = swModel.GetActiveSketch2
sketchPointArray = theSketch.GetSketchPoints2
pointCount = UBound(sketchPointArray) + 1
' For each SketchPoint
For i = 0 To (pointCount - 1)
' Set local SketchPoint object (optional)
' Set theSketchPoint = sketchPointArray(i)
' Get the coordinates
xValue = sketchPointArray(i).X 'meters
yValue = sketchPointArray(i).Y 'meters
zValue = sketchPointArray(i).Z 'meters
Debug.Print "---------------------------"
If (xValue < 0) Then
ExtraSpace = ""
Else
ExtraSpace = " "
End If
Debug.Print "X: " & ExtraSpace & Format(xValue * 1000, "0.000000") & " [mm]"
If (yValue < 0) Then
ExtraSpace = ""
Else
ExtraSpace = " "
End If
Debug.Print "Y: " & ExtraSpace & Format(yValue * 1000, "0.000000") & " [mm]"
If (zValue < 0) Then
ExtraSpace = ""
Else
ExtraSpace = " "
End If
Debug.Print "Z: " & ExtraSpace & Format(zValue * 1000, "0.000000") & " [mm]"
' <Do something useful with the data>
Next i
End Sub
RE: API Question...
Thanks but that doesn't fully answer my question. This bit tells me where sketch points are located relative to the origin of the component which contains the sketch. The task that I'm interested in accomplishing is to extrapolate the location of points relative to the origin of an assembly that contains the component which contains the sketch. Determining how to do this has proven to be a bit tougher to get my head around.
Thanks,
RHR
RE: API Question...
And yeah, those are a bit tough to wrap your head around, especially if you've never used transformation matricies before.