Hide Table of Contents

Create and Modify Closed Corner Feature Example (VBA)

This example shows how to create and modify a closed corner feature in a sheet metal part.

'------------------------------------------------------------------
' Preconditions:
' 1. Verify that the specified sheet metal part document to
'    open exists.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Opens the specified sheet metal part document.
' 2. Selects two faces.
' 3. Inserts a closed corner feature.
' 4. Modifies properties of the closed corner feature.
' 5. Examine the graphics area and Immediate window.
'
' NOTE: Because this part document 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 swFeature As SldWorks.Feature
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim swClosedCornerFeatureData As SldWorks.ClosedCornerFeatureData
Dim status As Boolean
Dim errors As Long
Dim warnings As Long
Dim fileName As String
Dim faces As Variant
Dim swFace As SldWorks.Face2
Dim i As Long
Sub main()
    Set swApp = Application.SldWorks
    fileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2017\tutorial\sheetmetal\formtools\cover.sldprt"
    Set swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
    Set swModelDocExt = swModel.Extension
    Set swSelectionMgr = swModel.SelectionManager    
    'Select the faces for the closed corner feature
    status = swModelDocExt.SelectByID2("", "FACE", 1.10595835492404E-02, 2.80018934407167E-02, 4.97348782814129E-02, True, 1, Nothing, 0)
    status = swModelDocExt.SelectByID2("", "FACE", 1.81424245698736E-02, 1.10595835492404E-02, 4.95671179450028E-02, True, 1073741824, Nothing, 0)    
    'Insert the closed corner feature
    swModel.InsertSheetMetalClosedCorner    
    'Select the closed corner feature
    status = swModelDocExt.SelectByID2("Closed Corner1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
    Set swFeature = swSelectionMgr.GetSelectedObject6(1, -1)
    Set swClosedCornerFeatureData = swFeature.GetDefinition    
    'Access closed corner feature
    status = swClosedCornerFeatureData.AccessSelections(swModel, Nothing)
        Debug.Print ("Original properties: ")
        Debug.Print ("  Corner type: " & swClosedCornerFeatureData.CornerType)
        Debug.Print ("  Gap distance: " & swClosedCornerFeatureData.GapDistance)
        Debug.Print ("  Open bend region? " & swClosedCornerFeatureData.OpenBendRegion)
        Debug.Print ("  Overlap/underlap ratio: " & swClosedCornerFeatureData.OverlapUnderlapRatio)
        faces = swClosedCornerFeatureData.faces
        For i = 0 To UBound(faces)
            Set swFace = faces(i)
            Debug.Print ("  Area of face " & i & ": " & swFace.GetArea * 1000 & " mm")
        Next i        
        Debug.Print ("Modified properties: ")
        swClosedCornerFeatureData.CornerType = swClosedCornerTypes_e.swClosedCornerTypeUnderlap
        swClosedCornerFeatureData.GapDistance = 0.005
        swClosedCornerFeatureData.OpenBendRegion = True
        swClosedCornerFeatureData.OverlapUnderlapRatio = 0.5
        Debug.Print ("  Corner type: " & swClosedCornerFeatureData.CornerType)
        Debug.Print ("  Gap distance: " & swClosedCornerFeatureData.GapDistance)
        Debug.Print ("  Open bend region? " & swClosedCornerFeatureData.OpenBendRegion)
        Debug.Print ("  Overlap/underlap ratio: " & swClosedCornerFeatureData.OverlapUnderlapRatio)        
        status = swFeature.ModifyDefinition(swClosedCornerFeatureData, swModel, Nothing)
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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create and Modify Closed Corner Feature Example (VBA)
*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) 2017 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.