Hide Table of Contents

Create Solid Body Surface Trim Feature Example (C#)

This example shows how to create a solid body surface trim feature.

// Preconditions:
// 1. Verify that the specified part to open exists.
// 2. Open the Immediate window.
// Postconditions:
// 1. Opens the specified part.
// 2. Creates Surface-Trim1.
// 3. Expand and examine Solid Bodies(1) in the FeatureManager 
//    design tree and examine the Immediate window.
// NOTE: Because the model is used elsewhere, do not save changes.
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
namespace Macro1CSharp.csproj
    public partial class SolidWorksMacro
        public void Main()
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            FeatureManager swFeatureManager = default(FeatureManager);
            Feature swFeature = default(Feature);
            bool status = false;
            string fileName = null;
            int errors = 0;
            int warnings = 0;
            fileName = "C:\\Program Files\\SolidWorks Corp\\SolidWorks\\samples\\tutorial\\api\\SurfaceTrimFeature.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, ""ref errors, ref warnings);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
            // Select surface features
            status = swModelDocExt.SelectByID2("""SURFACEBODY", -0.0446486526100784, 0.0218350174377093, 0.0123754341749418, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("""SURFACEBODY", -0.00815686270678384, 0.0415839719953865, 0.0242402652081068, true, 0, null, 0);
            // Select trimming surfaces to create solid body surface trim feature
            status = swFeatureManager.PreTrimSurface(truetruefalsetrue);
            status = swModelDocExt.SelectByID2("""SURFACEBODY", 0.0059504253577245, 0.0413800871671199, 0.0248740287174201, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("""SURFACEBODY", -0.037205042299604, 0.0343527327176432, 0.0123446167727934, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("""SURFACEBODY", -0.0104497983190015, -0.0472172176775487, 0.0233436625590571, true, 0, null, 0);
            Debug.Print("Solid body surface trim feature? " + swFeatureManager.SolidForTrim);
            swFeatureManager.SolidForTrim = true;
            Debug.Print("Solid body surface trim feature? " + swFeatureManager.SolidForTrim);
            swFeature = (Feature)swFeatureManager.PostTrimSurface(true);
        /// <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

Subject:   Feedback on Help Topics
Page:   Create Solid Body Surface Trim Feature Example (C#)
*   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) 2016 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.