Hide Table of Contents

Get and Fill Gaps in Body Example (VB.NET)

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

' Preconditions:
' 1. Open a model document that contains at least one body
'    with one or more gaps.
' 2. Open the Immediate window.
' Postconditions:
' 1. Identifies the number of gaps in each
'    body and fills each gap with a fill-surface
'    feature.
' 2. Examine the Immediate window and the FeatureManager
'    design tree.
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
    Public Sub main()
        Dim swModel As ModelDoc2
        Dim swPart As PartDoc
        Dim vBodyArr As Object
        Dim vBody As Object
        Dim swBody As Body2
        Dim i As Integer
        swModel = swApp.ActiveDoc
        swPart = swModel
        Debug.Print("File = " & swModel.GetPathName)
        For i = 0 To 5
            vBodyArr = swPart.GetBodies2(i, False)
            If Not vBodyArr Is Nothing Then
                Debug.Print("  NumBody[" & i & "] = " & UBound(vBodyArr) + 1)
                For Each vBody In vBodyArr
                    swBody = vBody
                    ProcessBody(swApp, swModel, swBody)
                Next vBody
            End If
        Next i
    End Sub
    Sub ProcessBody(ByVal swApp As SldWorks, ByVal swModel As ModelDoc2, ByVal swBody As Body2)
        Dim nRetval1 As Integer
        Dim nRetval2 As Integer
        Dim swDiagnose As DiagnoseResult
        Dim vCoEdgeArr As Object
        Dim vCoEdge As Object
        Dim swCoEdge As CoEdge
        Dim swEdge As Edge
        Dim swEnt As Entity
        Dim swSelMgr As SelectionMgr
        Dim swSelData As SelectData
        Dim swFeatMgr As FeatureManager
        Dim swFaultEnt As FaultEntity
        Dim swFeat As Feature
        Dim nNumGap As Integer
        Dim i As Integer
        Dim bRet As Boolean
        swSelMgr = swModel.SelectionManager
        swSelData = swSelMgr.CreateSelectData
        swFeatMgr = swModel.FeatureManager
        swDiagnose = swBody.Diagnose
        swFaultEnt = swBody.Check3
        nRetval1 = swFaultEnt.Count
        swFaultEnt = swBody.Check3
        nRetval2 = swFaultEnt.Count
        swSelData.Mark = 257
        nNumGap = swDiagnose.GetGapsCount
        Debug.Print("    Body check1                        = " & nRetval1)
        Debug.Print("      Body check2 (Number of faults)   = " & nRetval2)
        Debug.Print("    Number of gaps                     = " & nNumGap)
        For i = 1 To nNumGap
            vCoEdgeArr = swDiagnose.GetCoEdgesAtGap(i - 1)
            For Each vCoEdge In vCoEdgeArr
                swCoEdge = vCoEdge
                swEdge = swCoEdge.GetEdge
                swEnt = swEdge
                bRet = swEnt.Select4(True, swSelData)
            Next vCoEdge
            swFeat = swFeatMgr.InsertFillSurface2(3, swFeatureFillSurfaceOptions_e.swOptimizeSurface, swSelData, swContactType_e.swContact, NothingNothing)
        Next i
    End Sub
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    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:   Get and Fill Gaps in Body 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) 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.