Hide Table of Contents

Create Split Feature Example (VBA)

This example shows how to create a Split feature.

'----------------------------------------------------------------------------
' Preconditions:
' 1. Open a part document that contains a body that is bisected by
'    Top Plane.
' 2. Verify that c:\temp exists.
' 3. Open an Immediate window.
'
' Postconditions:
' 1. Creates Split1.
' 2. Saves a split body to c:\temp\Body1.sldprt.
' 3. Inspect the Immediate window, FeatureManager design tree, graphics area,
'    and c:\temp.
'---------------------------------------------------------------------------

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeat As SldWorks.Feature
Dim swFeatMgr As SldWorks.FeatureManager
Dim swSplitBodyFeat As SldWorks.SplitBodyFeatureData
Dim boolstatus As Boolean

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swModelDocExt = swModel.Extension
    Set swSelMgr = swModel.SelectionManager
    Set swFeatMgr = swModel.FeatureManager

    'Select the cutting tool
    boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)

    'Get bodies resulting from the split operation
    Dim vResultingBodies As Variant
    vResultingBodies = swFeatMgr.PreSplitBody2

    swModel.ClearSelection2 True

    Dim vBodiesToMark As Variant
    Dim vBodyNames As Variant
    Dim vBodyOrigins As Variant
    Dim bodiesToMark(1) As Object
    Dim bodyNames(1) As String
    Dim bodyOrigins(1) As Object

    'Set up the arrays for the post-split operation

    'Specify the origins of the bodies to save; specify Nothing to use the default origins
    Set bodyOrigins(0) = Nothing
    Set bodyOrigins(1) = Nothing

    Set bodiesToMark(0) = vResultingBodies(0)
    Set bodiesToMark(1) = vResultingBodies(1)

    'Save the first body to a separate part document
    'Substitute the name of the actual folder where to save the body
    bodyNames(0) = "c:\temp\Body1.sldprt"

    'Do not save the second body
    bodyNames(1) = ""

    vBodiesToMark = bodiesToMark
    vBodyNames = bodyNames
    vBodyOrigins = bodyOrigins

    'Create the Split feature, consuming all split bodies
    Set swFeat = swFeatMgr.PostSplitBody2((vBodiesToMark), True, (vBodyOrigins), (vBodyNames), "")

    If (Not swFeat Is Nothing) Then
        Debug.Print "Split feature: " & swFeat.Name
        Set swSplitBodyFeat = swFeat.GetDefinition
        Debug.Print "Consumed? " & swSplitBodyFeat.Consume
        Debug.Print " "
    End If

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:   Create Split Feature 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) 2019 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.