Hide Table of Contents

Remove Edge from Edge Flange Feature Example (VBA)

This example shows how to remove an edge from an edge flange feature in a sheet metal part.

'----------------------------------------------------------------------------
' Preconditions: 
' 1. Open:
'    install_dir\samples\tutorial\api\SM1-remove-edges.sldprt
' 2. Open the Immediate window.
'
' Postconditions: 
' 1. One edge is removed from Edge-Flange1.
' 2. Verify by examining the output printed to the Immediate window.
'
' NOTE: Because the model is used elsewhere,
' do not save changes when closing it.
' ---------------------------------------------------------------------------
Option Explicit
Sub Main()
    Dim swApp               As SldWorks.SldWorks
    Dim swDocument          As SldWorks.PartDoc
    Dim swSelectionManager  As SldWorks.SelectionMgr
    Dim swEdgeFlangeData    As SldWorks.EdgeFlangeFeatureData
    Dim swFeature           As SldWorks.Feature
    Dim lNumEdges           As Long
    Dim aEdgesToRemove()    As SldWorks.Edge
    Dim lIdx                As Long
    Dim bStatus             As Boolean
    Dim lNumEdgesToRemove   As Long
    Dim vEdgesToRemove      As Variant
    Dim vEdges              As Variant
    Dim nStatus             As SwConst.swEdgeFlangeError_e
    Set swApp = Application.SldWorks
    Set swDocument = swApp.ActiveDoc
    Set swSelectionManager = swDocument.SelectionManager
    bStatus = swDocument.Extension.SelectByID2("Edge-Flange1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
    Set swFeature = swSelectionManager.GetSelectedObject6(1, 0)
    swDocument.ClearSelection2 True
    Set swEdgeFlangeData = swFeature.GetDefinition
    swEdgeFlangeData.AccessSelections swDocument, Nothing
    Debug.Print "Number of edges: " & swEdgeFlangeData.GetEdgeCount   
    vEdges = swEdgeFlangeData.Edges    
    lNumEdges = UBound(vEdges) - LBound(vEdges) + 1    
    '
    ' Select number of edges to remove
    '
    Select Case (1)    
        Case 1
            ' Remove one edge
            lNumEdgesToRemove = 1           
        Case 2
            ' Remove all edges
            lNumEdgesToRemove = lNumEdges            
        Case 3
            ' Remove no edges
            lNumEdgesToRemove = 0        
    End Select
    
    vEdgesToRemove = Empty    
    If (lNumEdgesToRemove >= 1) Then
        ReDim aEdgesToRemove(lNumEdgesToRemove - 1)
        For lIdx = 0 To (lNumEdgesToRemove - 1)
            Set aEdgesToRemove(lIdx) = vEdges(lIdx)
        Next lIdx
        vEdgesToRemove = aEdgesToRemove
    End If    
    nStatus = swEdgeFlangeData.RemoveEdges(vEdgesToRemove)
    Debug.Print "Edge removal error code = " & swEdgeFlangeError2String(nStatus)
    
    bStatus = swFeature.ModifyDefinition(swEdgeFlangeData, swDocument, Nothing) 
    Debug.Print "Status of modify definition = " & bStatus    
    swEdgeFlangeData.AccessSelections swDocument, Nothing    
    vEdges = Empty    
    vEdges = swEdgeFlangeData.Edges
    
    If (Not IsEmpty(vEdges)) Then
        lNumEdges = UBound(vEdges) - LBound(vEdges) + 1
        Debug.Print "Number of edges in edge flange = " & lNumEdges
    Else
        Debug.Print "Number of edges in edge flange = 0"
    End If  
    swEdgeFlangeData.ReleaseSelectionAccess
    
End Sub
Private Function swEdgeFlangeError2String(ByVal nStatus As SwConst.swEdgeFlangeError_e) As String
    Select Case (nStatus)
        Case 0
            swEdgeFlangeError2String = "no error"
        Case swEdgeFlangeError_e.swEdgeFlangeError_EdgeAlreadyExists
            swEdgeFlangeError2String = "edge already exists"
        Case swEdgeFlangeError_e.swEdgeFlangeError_EdgeNotSpecified
            swEdgeFlangeError2String = "edge not specified"
        Case swEdgeFlangeError_e.swEdgeFlangeError_NumberOfEdgesAndSketchesNotEqual
            swEdgeFlangeError2String = "number mismatch"
        Case swEdgeFlangeError_e.swEdgeFlangeError_SketchNotSpecified
            swEdgeFlangeError2String = "sketch not specified"
        Case Else
            swEdgeFlangeError2String = "unknown error"
    End Select
    
End Function


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:   Remove Edge from Edge Flange 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) 2013 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.