Hide Table of Contents

Create Split-body Feature Example (VB.NET)

This example shows how to create a split-body 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 split-body feature, Split1.
' 2. Saves a split body to c:\temp\Body1.sldprt.
' 3. Inspect the Immediate window, FeatureManager design tree, graphics area,
'    and c:\temp.

Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
    Dim swModel As ModelDoc2
    Dim swSelMgr As SelectionMgr
    Dim swModelDocExt As ModelDocExtension
    Dim swFeat As Feature
    Dim swFeatMgr As FeatureManager
    Dim swSplitBodyFeat As SplitBodyFeatureData
    Dim boolstatus As Boolean
    Sub main()
        swModel = swApp.ActiveDoc
        swModelDocExt = swModel.Extension
        swSelMgr = swModel.SelectionManager
        swFeatMgr = swModel.FeatureManager
        'Select the cutting tool
        boolstatus = swModelDocExt.SelectByID2("Top Plane""PLANE", 0, 0, 0, True, 0, Nothing, 0)
        'Get bodies that will result from the split operation
        Dim vResultingBodies(3) As Object
        vResultingBodies = swFeatMgr.PreSplitBody2
        Dim vBodyNames As Object
        Dim bodiesToMark(1) As Body2
        Dim bodyNames(1) As String
        Dim bodyOrigins(1) As Vertex
        'Set up the arrays for the post-split operation
        'Assign the origins of bodies to save; set to nothing to use default origins
        bodyOrigins(0) = Nothing
        bodyOrigins(1) = Nothing
        bodiesToMark(0) = vResultingBodies(0)
        bodiesToMark(1) = vResultingBodies(1)
        'Save the body marked 0
        bodyNames(0) = "c:\temp\Body1.sldprt"
        'Do not save body marked 1
        bodyNames(1) = ""
        Dim preSplitBodies() As DispatchWrapper
        preSplitBodies = ObjectArrayToDispatchWrapperArray((bodiesToMark))
        vBodyNames = bodyNames
        Dim originsToUse() As DispatchWrapper
        originsToUse = ObjectArrayToDispatchWrapperArray((bodyOrigins))
        'Create the split-body feature
        swFeat = swFeatMgr.PostSplitBody((preSplitBodies), True, (originsToUse), (vBodyNames))
        If (Not swFeat Is NothingThen
            Debug.Print("Name of split-body feature = " & swFeat.Name)
            swSplitBodyFeat = swFeat.GetDefinition
            Debug.Print("Split-body feature is consumed = " & swSplitBodyFeat.Consume)
            Debug.Print(" ")
        End If
    End Sub
    Function ObjectArrayToDispatchWrapperArray(ByVal Objects As Object()) As DispatchWrapper()
        Dim ArraySize As Integer
        ArraySize = Objects.GetUpperBound(0)
        Dim d(ArraySize) As DispatchWrapper
        Dim ArrayIndex As Integer
        For ArrayIndex = 0 To ArraySize
            d(ArrayIndex) = New DispatchWrapper(Objects(ArrayIndex))
        Return d
    End Function
    Public swApp As SldWorks
End Class

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

Subject:   Feedback on Help Topics
Page:   Create Split-body Feature Example (VB.NET)
*   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:


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

Web Help Content Version: API Help (English only) 2017 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.