Hide Table of Contents

Get and Fill Gaps in Body Example (C#)

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.
//---------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace DiagnoseResultCSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            PartDoc swPart = default(PartDoc);
            object[] vBodyArr = null;
            Body2 swBody = default(Body2);
            int i = 0;
            int length = 0;
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swPart = (PartDoc)swModel;
            Debug.Print("File = " + swModel.GetPathName());
            for (i = 0; i <= 5; i++)
            {
                vBodyArr = (object[])swPart.GetBodies2(i, false);
                if ((vBodyArr != null))
                {
                    length = vBodyArr.GetLength(0);
                    Debug.Print("  NumBody[" + i + "] = " + length.ToString());
                    foreach (Body2 vBody in vBodyArr)
                    {
                        swBody = vBody;
                        ProcessBody(swApp, swModel, swBody);
                    }
                }
            }
 
        }
 
        public void ProcessBody(SldWorks swApp, ModelDoc2 swModel, Body2 swBody)
        {
            int nRetval1 = 0;
            int nRetval2 = 0;
            DiagnoseResult swDiagnose = default(DiagnoseResult);
            object[] vCoEdgeArr = null;
            CoEdge swCoEdge = default(CoEdge);
            Edge swEdge = default(Edge);
            Entity swEnt = default(Entity);
            SelectionMgr swSelMgr = default(SelectionMgr);
            SelectData swSelData = default(SelectData);
            FeatureManager swFeatMgr = default(FeatureManager);
            Feature swFeat = default(Feature);
            FaultEntity swFaultEnt = default(FaultEntity);
            int nNumGap = 0;
            int i = 0;
            bool bRet = false;
 
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            swSelData = (SelectData)swSelMgr.CreateSelectData();
            swFeatMgr = (FeatureManager)swModel.FeatureManager;
            swDiagnose = (DiagnoseResult)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; i <= nNumGap; i++)
            {
                swModel.ClearSelection2(true);
                vCoEdgeArr = (object[])swDiagnose.GetCoEdgesAtGap(i - 1);
                foreach (CoEdge vCoEdge in vCoEdgeArr)
                {
                    swCoEdge = (CoEdge)vCoEdge;
                    swEdge = (Edge)swCoEdge.GetEdge();
                    swEnt = (Entity)swEdge;
                    bRet = swEnt.Select4(true, swSelData);
                }
                swFeat = (Feature)swFeatMgr.InsertFillSurface2(3, (int)swFeatureFillSurfaceOptions_e.swOptimizeSurface, swSelData, (int)swContactType_e.swContact, nullnull);
            }
 
        }
 
 
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}


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 (C#)
*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) 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.