Hide Table of Contents

Create Split-body Feature Example (VBA)

This example shows how to create a split-body feature.

 

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

'

' Precondition: Part document is open that

'               contains a body to split.

'

' Postcondition: Split body feature is created with

'               the split bodies consumed.

'

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

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)

    

    'Perform the pre-split operation (get bodies that will result from split operation)

    Dim vResultingBodies As Variant

    vResultingBodies = swFeatMgr.PreSplitBody

    

    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

    

    ' Select the origin of the body to save

    boolstatus = swModelDocExt.SelectByID2("", "VERTEX", -0.07260453968254, 0.07175701587302, 0.05, False, 0, Nothing, 0)

    

    'Set up the arrays for the post-split operation

    Set bodiesToMark(0) = vResultingBodies(0)

    'Save body marked 0

    'Substitute the name of the actual folder where to save the body

    bodyNames(0) = "e:\splitbodyconsume\Body1.sldprt"

    Set bodyOrigins(0) = swSelMgr.GetSelectedObject6(1, 0)

    Set bodiesToMark(1) = vResultingBodies(1)

    'Do not save body marked 1

    bodyNames(1) = ""

    'If you do not want to assign origin, set it to nothing so that the default origin is used

    Set bodyOrigins(1) = Nothing

    

    vBodiesToMark = bodiesToMark

    vBodyNames = bodyNames

    vBodyOrigins = bodyOrigins

    

    'Perform the post-split operation (create the split-body feature)

    Set swFeat = swFeatMgr.PostSplitBody((vBodiesToMark), True, (vBodyOrigins), (vBodyNames))

    

    If (Not swFeat Is Nothing) Then

        Debug.Print "Name of split-body feature = " & swFeat.Name

        Set swSplitBodyFeat = swFeat.GetDefinition

        Debug.Print "Is the split-body feature 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-body 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) 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.