Hide Table of Contents

Get and Fill Gaps in Body Example (VBA)

This example shows how to get and fill the gaps in a body.

 

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

'

' Preconditions:  Model document is open and contains

'                 at least one body with one or more gaps.

'

' Postconditions: A Surface-Fill feature fills each gap.

'

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

Option Explicit

Public Enum swBodyType_e

    swSolidBody = 0

    swSheetBody = 1

    swWireBody = 2

    swMinimumBody = 3

    swGeneralBody = 4

    swEmptyBody = 5

End Enum

Sub ProcessBody _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swBody As SldWorks.body2 _

)

    Dim nRetval1                As Long

    Dim nRetval2                As Long

    Dim swDiagnose              As SldWorks.DiagnoseResult

    Dim vCoEdgeArr              As Variant

    Dim vCoEdge                 As Variant

    Dim swCoEdge                As SldWorks.CoEdge

    Dim swEdge                  As SldWorks.Edge

    Dim swEnt                   As SldWorks.entity

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim swSelData               As SldWorks.SelectData

    Dim swFeatMgr               As SldWorks.FeatureManager

    Dim swFeat                  As SldWorks.feature

    Dim nNumGap                 As Long

    Dim i                       As Long

    Dim bRet                    As Boolean

    

    Set swSelMgr = swModel.SelectionManager

    Set swSelData = swSelMgr.CreateSelectData

    Set swFeatMgr = swModel.FeatureManager

    Set swDiagnose = swBody.Diagnose

    

    nRetval1 = swBody.Check2

    nRetval2 = swBody.Check2

    swSelData.mark = 1

        

    nNumGap = swDiagnose.GetGapsCount

    For i = 1 To nNumGap

        swModel.ClearSelection2 True

    

        vCoEdgeArr = swDiagnose.GetCoEdgesAtGap(i - 1)

        For Each vCoEdge In vCoEdgeArr

            Set swCoEdge = vCoEdge

            Set swEdge = swCoEdge.GetEdge

            Set swEnt = swEdge

            

            bRet = swEnt.Select4(True, swSelData): Debug.Assert bRet

        Next vCoEdge

        

        Set swFeat = swFeatMgr.InsertFillSurface(3)

    Next i

            

    Debug.Print "    Body check1                        = " & nRetval1

    Debug.Print "      Body check2 (Number of faults)   = " & nRetval2

    Debug.Print "    Number of gaps                     = " & nNumGap

End Sub

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swPart                  As SldWorks.PartDoc

    Dim vBodyArr                As Variant

    Dim vBody                   As Variant

    Dim swBody                  As SldWorks.body2

    Dim i                       As Long

    Dim bRet                    As Boolean

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swPart = swModel

        

    Debug.Print "File = " & swModel.GetPathName

    For i = 0 To 5

        vBodyArr = swPart.GetBodies2(i, False)

        If Not IsEmpty(vBodyArr) Then

            Debug.Print "  NumBody[" & i & "] = " & UBound(vBodyArr) + 1

            For Each vBody In vBodyArr

                Set swBody = vBody

                

                ProcessBody swApp, swModel, swBody

            Next vBody

        End If

    Next i

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:   Get and Fill Gaps in Body 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) 2012 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.