Hide Table of Contents

Split Closed Sketch Segment Example (VBA)

This example shows how to split a closed sketch segment.

'---------------------------------------------------------------
' Preconditions: 
' 1. Open a new part document.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Opens a sketch.
' 2. Creates a closed spline.
' 3. Splits the spline into two segments.
' 4. Examine the Immediate window.
'----------------------------------------------------------------

Option Explicit

Dim SwApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSketchSegment As SldWorks.SketchSegment
Dim skSegmentArray As Variant
Dim boolstatus As Boolean

Sub main()

    Set SwApp = Application.SldWorks
    Set swModel = SwApp.ActiveDoc

   SwApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swSketchInference, False

    boolstatus = swModel.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
    swModel.SketchManager.InsertSketch True
    swModel.ClearSelection2 True
   

    Dim pointArray As Variant
    Dim points() As Double
    ReDim points(0 To 20) As Double
    points(0) = -2.43607314462504E-02
    points(1) = 4.04155099449417E-02
    points(2) = 0
    points(3) = -8.49151208568891E-04
    points(4) = 4.70352752545802E-02
    points(5) = 0
    points(6) = 0
    points(7) = 3.95024388677502E-02
    points(8) = 0
    points(9) = -5.30037270987752E-03
    points(10) = 3.58501545589842E-02
    points(11) = 0
    points(12) = -7.12651486426054E-03
    points(13) = 2.83173181721542E-02
    points(14) = 0
    points(15) = -0.023219392599761
    points(16) = 2.95727909032925E-02
    points(17) = 0
    points(18) = -2.43607314462504E-02
    points(19) = 4.04155099449417E-02
    points(20) = 0
    pointArray = points
    Dim skSegment As Object
    Set skSegment = swModel.SketchManager.CreateSpline((pointArray))
    swModel.ViewZoomtofit2
   

    skSegmentArray = swModel.SketchManager.SplitClosedSegment(-2.43607314462504E-02, 4.04155099449417E-02, 0#, -0.023219392599761, 2.95727909032925E-02, 0#)

    ' Close the sketch and rebuild
    swModel.SketchManager.Insert3DSketch True

    Debug.Print "Number of segments in sketch = " & UBound(skSegmentArray) + 1

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:   Split Closed Sketch Segment 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) 2024 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.