Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

API Question...

Status
Not open for further replies.

RawheadRex

Mechanical
Feb 9, 2001
236
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
 
Replies continue below

Recommended for you

Look in SolidWorks Main Menu/Help/SolidWorks and Add-Ins API Help Topics/Contents (Tab)/SolidWorks API Help/Examples and Projects/Visual Basic (VB) Examples/R - T/Sketch Points and look at the Get Sketch Points example.

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
 
Hi Ken,

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
 
You need to look into the MathXxx type objects - MathVector, MathUtility, MathPoint, MathTransform, etc.

And yeah, those are a bit tough to wrap your head around, especially if you've never used transformation matricies before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor