Hide Table of Contents

Create Body From Selected Faces Example

This example shows how to create a body from one or more selected faces using:

  • IBody2::CreateBodyFromFaces

  • IPartDoc::CreateFeatureFromBody3

 

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

'

' Problem:

'       This example shows how to use some of

'       the geometry and topolgy APIs to

'       construct a temporary API body from a

'       set of selected faces and then create a solid

'       body feature from this temporary body.

'

 

' Preconditions:

'       (1) Part is open.

'       (2) At least one face is selected.

'

' Postconditions: If the selected faces can be knitted into a solid,

'           then a new part is created and the solid (from the

'           selected faces) is inserted as an imported solid

'           body feature.

'

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

Option Explicit

Public Enum swBodyType_e

    swAllBodies = -1

    swSolidBody = 0

    swSheetBody = 1

    swWireBody = 2

    swMinimumBody = 3

    swGeneralBody = 4

    swEmptyBody = 5

End Enum

Public Enum swCreateFeatureBodyOpts_e

    swCreateFeatureBodyCheck = &H1

    swCreateFeatureBodySimplify = &H2

End Enum

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swPart                  As SldWorks.PartDoc

    Dim swNewPart               As SldWorks.PartDoc

    Dim swModeller              As SldWorks.Modeler

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim swSelFace()             As SldWorks.face2

    Dim vFaceList               As Variant

    Dim swBody                  As SldWorks.body2

    Dim swNewBody               As SldWorks.body2

    Dim swFeat                  As SldWorks.feature

    Dim nSelCount               As Long

    Dim i                       As Long

    Dim bRet                    As Boolean

    

    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swPart = swModel

    Set swSelMgr = swModel.SelectionManager

    Set swModeller = swApp.GetModeler

    

    nSelCount = swSelMgr.GetSelectedObjectCount

    

    ReDim swSelFace(nSelCount - 1)

    

    For i = 1 To nSelCount

        Set swSelFace(i - 1) = swSelMgr.GetSelectedObject5(i)

    Next

    

    vFaceList = swSelFace

    

    Set swBody = swPart.CreateNewBody

    Set swNewBody = swBody.CreateBodyFromFaces(nSelCount, (vFaceList))

    

    If swNewBody Is Nothing Then

        Debug.Print "Failed to form solid body from selected faces."

        

        Exit Sub

    End If

    

    Debug.Assert swSolidBody = swNewBody.GetType

    

    Set swNewPart = swApp.NewPart

    

    ' Force creation of a solid body feature

    Set swFeat = swNewPart.CreateFeatureFromBody3(swNewBody, False, _

                    swCreateFeatureBodyCheck + swCreateFeatureBodySimplify)

                    

    ' Must be able to create a solid body feature from a solid body

    Debug.Assert Not swFeat Is Nothing

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 Body From Selected Faces 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.