Hide Table of Contents

Insert Surface-cut Feature Example (VB.NET)

This example shows how to insert a surface-cut feature.

'------------------------------------------------------------------------------
' Preconditions: 
' 1. Verify that the specified part to open exists.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Opens the part whose intersecting solid bodies 
'    to cut with a plane.
' 2. Creates a plane named Plane1.
' 3. Selects Plane1 to cut all intersecting solid bodies.
' 4. Inserts the surface-cut feature, which cuts all intersecting 
'    solid bodies by the plane.
' 5. Examine the Immediate window and graphics area to verify.
'
' NOTE: Because this part document is used elsewhere, do not save changes.
'------------------------------------------------------------------------------
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 swModelDocExt As ModelDocExtension
        Dim swFeature As Feature
        Dim swFeatureManager As FeatureManager
        Dim swRefPlane As RefPlane
        Dim swSurfaceCutFeature As SurfCutFeatureData
        Dim status As Boolean
        Dim fileName As String
        Dim errors As Integer, warnings As Integer
 
        ' Open part to cut with a plane
        fileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\multibody\multi_inter.sldprt"
        swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swModelDocExt = swModel.Extension
 
        ' Create and select the plane to cut 
        ' all intersecting solid bodies in the part
        status = swModelDocExt.SelectByID2("Front""PLANE", 0, 0, 0, True, 0, Nothing, 0)
        swFeatureManager = swModel.FeatureManager
        swRefPlane = swFeatureManager.InsertRefPlane(swRefPlaneReferenceConstraints_e.swRefPlaneReferenceConstraint_Distance, 0.045, 0, 0, 0, 0)
        status = swModelDocExt.SelectByID2("Plane1""PLANE", 0, 0, 0, True, 0, Nothing, 0)
 
        ' Insert a surface-cut feature that cuts all
        ' intersecting solid bodies
        swFeature = swFeatureManager.InsertCutSurface(False, 0, FalseTrue, Nothing, errors)
        Debug.Print("Were any errors generated by the surface cut (0 = no errors)? " & errors)

        ' Get surface-cut feature and some properties
        swSurfaceCutFeature = swFeature.GetDefinition
        Debug.Print("Name of surface-cut feature: " & swFeature.Name)
        Debug.Print(" Is feature scope on? " & swSurfaceCutFeature.FeatureScope)
        Debug.Print(" Number of bodies cut by the plane: " & swSurfaceCutFeature.GetFeatureScopeBodiesCount)
        Debug.Print(" Is auto-select on? " & swSurfaceCutFeature.AutoSelect)
    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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Insert Surface-cut Feature Example (VB.NET)
*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.