×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

API Question...

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

RE: API Question...

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

RE: API Question...

(OP)
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

RE: API Question...

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources