Hide Table of Contents

Get Sketch Segment and Curve Data Example (VBA)

This example shows how to get data about a sketch segment and curve.

 

'---------------------------------------------

'

' Preconditions:

'             (1) Model document is open.

'             (2) Sketch segment is selected.

'

' Postconditions: None

'

'---------------------------------------------

Option Explicit

Public Enum swSkSegments_e

    swSketchLINE = 0

    swSketchARC = 1

    swSketchELLIPSE = 2

    swSketchSPLINE = 3

    swSketchTEXT = 4

    swSketchPARABOLA = 5

End Enum

' Define two types

Type DoubleRec

    dValue As Double

End Type

Type Long2Rec

    iLower As Long

    iUpper As Long

End Type

' Extract two integer values from of a single double value

' by assigning a DoubleRec to the double value and

' copying the value to a Long2Rec and

' extracting the integer values

Function ExtractFields _

( _

    ByVal dValue As Double, _

    iLower As Long, _

    iUpper As Long _

)

    Dim dr                      As DoubleRec

    Dim i2r                     As Long2Rec

    ' Set the double value

    dr.dValue = dValue

    ' Copy the values

    LSet i2r = dr

    ' Extract the values

    iLower = i2r.iLower

    iUpper = i2r.iUpper

End Function

Sub ProcessCurve _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swCurve As SldWorks.curve _

)

    Dim nStartParam             As Double

    Dim nEndParam               As Double

    Dim bIsClosed               As Boolean

    Dim bIsPeriodic             As Boolean

    Dim vStartEval              As Variant

    Dim vEndEval                As Variant

    Dim nSuccessStart           As Long

    Dim nEndStart               As Long

    Dim nDummy                  As Long

    Dim bRet                    As Boolean

    

    bRet = swCurve.GetEndParams(nStartParam, nEndParam, bIsClosed, bIsPeriodic): Debug.Assert bRet

    vStartEval = swCurve.Evaluate(nStartParam)

    vEndEval = swCurve.Evaluate(nEndParam)

    

    ExtractFields vStartEval(6), nSuccessStart, nDummy

    ExtractFields vEndEval(6), nEndStart, nDummy

    

    Debug.Print "    IsClosed       = " & bIsClosed

    Debug.Print "    IsPeriodic     = " & bIsPeriodic

    Debug.Print "    IsTrimmed      = " & swCurve.IsTrimmedCurve

    Debug.Print "    Start"

    Debug.Print "      Point        = (" & vStartEval(0) * 1000# & ", " & vStartEval(1) * 1000# & ", " & vStartEval(2) * 1000# & ") mm"

    Debug.Print "      Tangent      = (" & vStartEval(3) & ", " & vStartEval(4) & ", " & vStartEval(5) & ")"

    Debug.Print "      Success      = " & nSuccessStart

    Debug.Print "    Finish"

    Debug.Print "      Point        = (" & vEndEval(0) * 1000# & ", " & vEndEval(1) * 1000# & ", " & vEndEval(2) * 1000# & ") mm"

    Debug.Print "      Tangent      = (" & vEndEval(3) & ", " & vEndEval(4) & ", " & vEndEval(5) & ")"

    Debug.Print "      Success      = " & nEndStart

End Sub

Sub main()

    Dim sSkSegmentsName(5)      As String

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim swSkSeg                 As SldWorks.SketchSegment

    Dim swCurve                 As SldWorks.curve

    Dim swSkFeat                As SldWorks.feature

    Dim swSketch                As SldWorks.sketch

    Dim vID                     As Variant

    Dim bRet                    As Boolean

    

    sSkSegmentsName(swSketchLINE) = "swSketchLINE"

    sSkSegmentsName(swSketchARC) = "swSketchARC"

    sSkSegmentsName(swSketchELLIPSE) = "swSketchELLIPSE"

    sSkSegmentsName(swSketchSPLINE) = "swSketchSPLINE"

    sSkSegmentsName(swSketchTEXT) = "swSketchTEXT"

    sSkSegmentsName(swSketchPARABOLA) = "swSketchPARABOLA"

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    Set swSkSeg = swSelMgr.GetSelectedObject5(1)

    Set swCurve = swSkSeg.GetCurve

    Set swSkFeat = swSkSeg.GetSketch

    Set swSketch = swSkFeat.GetSpecificFeature

    

    vID = swSkSeg.GetId

    

    Debug.Print "Feature = " & swSkFeat.Name & " [" & swSketch.Is3D & "]"

    Debug.Print "  Sketch segment data"

    Debug.Print "    ID = [" & vID(0) & "," & vID(1) & "]"

    Debug.Print "      Type                 = " & sSkSegmentsName(swSkSeg.GetType)

    Debug.Print "      ConstGeom            = " & swSkSeg.ConstructionGeometry

    

    Debug.Print "  Curve data"

    ProcessCurve swApp, swModel, swCurve

End Sub

'---------------------------------------------



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Sketch Segment and Curve Data Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2013 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.