Hide Table of Contents

Create Solid Body Surface Trim Feature Example (VBA)

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.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeatureManager As SldWorks.FeatureManager
Dim swFeature As SldWorks.Feature
Dim status As Boolean
Dim fileName As String
Dim errors As Long
Dim warnings As Long
Sub main()
    Set swApp = Application.SldWorks
    fileName = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\api\SurfaceTrimFeature.sldprt"
    Set swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
    Set swModelDocExt = swModel.Extension
    Set swFeatureManager = swModel.FeatureManager    
    ' Select surface features
    status = swModelDocExt.SelectByID2("", "SURFACEBODY", -4.46486526100784E-02, 2.18350174377093E-02, 1.23754341749418E-02, True, 0, Nothing, 0)
    status = swModelDocExt.SelectByID2("", "SURFACEBODY", -8.15686270678384E-03, 4.15839719953865E-02, 2.42402652081068E-02, True, 0, Nothing, 0)    
    ' Select trimming surfaces to create solid body surface trim feature
    status = swFeatureManager.PreTrimSurface(True, True, False, True)
    status = swModelDocExt.SelectByID2("", "SURFACEBODY", 5.9504253577245E-03, 4.13800871671199E-02, 2.48740287174201E-02, True, 0, Nothing, 0)
    status = swModelDocExt.SelectByID2("", "SURFACEBODY", -0.037205042299604, 3.43527327176432E-02, 1.23446167727934E-02, True, 0, Nothing, 0)
    status = swModelDocExt.SelectByID2("", "SURFACEBODY", -1.04497983190015E-02, -4.72172176775487E-02, 2.33436625590571E-02, True, 0, Nothing, 0)
    Debug.Print "Solid body surface trim feature? " & swFeatureManager.SolidForTrim
    swFeatureManager.SolidForTrim = True
    Debug.Print "Solid body surface trim feature? " & swFeatureManager.SolidForTrim
    Set swFeature = swFeatureManager.PostTrimSurface(True)    
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

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