Hide Table of Contents

Remove Edge from Edge Flange Feature Example (C#)

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 in the Immediate window.
//
// NOTE: Because the model is used elsewhere,
// do not save changes when closing it.
// ---------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
 
namespace RemoveEdgesFromEdgeFlange_CSharp.csproj
{
    partial class SolidWorksMacro
    {
        public void Main()
        {
            ModelDoc2 swDocument = default(ModelDoc2);
            SelectionMgr swSelectionManager = default(SelectionMgr);
            EdgeFlangeFeatureData swEdgeFlangeData = default(EdgeFlangeFeatureData);
            Feature swFeature = default(Feature);
            int lNumEdges = 0;
            Edge[] aEdgesToRemove = null;
            int lIdx = 0;
            bool bStatus = false;
            int lNumEdgesToRemove = 0;
            object[] vEdgesToRemove = null;
            object[] vEdges = null;
            swEdgeFlangeError_e nStatus = default(swEdgeFlangeError_e);
            ModelDocExtension modDocExt = default(ModelDocExtension);
 
            swDocument = (ModelDoc2)swApp.ActiveDoc;
            swSelectionManager = (SelectionMgr)swDocument.SelectionManager;
 
            modDocExt = (ModelDocExtension)swDocument.Extension;
            bStatus = modDocExt.SelectByID2("Edge-Flange1""BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swFeature = (Feature)swSelectionManager.GetSelectedObject6(1, 0);
 
            swEdgeFlangeData = (EdgeFlangeFeatureData)swFeature.GetDefinition();
 
            swEdgeFlangeData.AccessSelections(swDocument, null);

            vEdges = (object[])swEdgeFlangeData.Edges;
            lNumEdges = vEdges.GetUpperBound(0) - vEdges.GetLowerBound(0) + 1;
            Debug.Print("Number of edges in edge flange = " + swEdgeFlangeData.GetEdgeCount());
 
            //
            // Specify number of edges to remove
            //
            lNumEdgesToRemove = 1;
 
            vEdgesToRemove = null;
            aEdgesToRemove = new Edge[lNumEdgesToRemove];
 
            if ((lNumEdgesToRemove >= 1))
            {
                for (lIdx = 0; lIdx <= (lNumEdgesToRemove - 1); lIdx++)
                {
                    aEdgesToRemove[lIdx] = (Edge)vEdges[lIdx];
                }
                vEdgesToRemove = aEdgesToRemove;
            }
 
            nStatus = (swEdgeFlangeError_e)swEdgeFlangeData.RemoveEdges(vEdgesToRemove);
            Debug.Print("Edge removal error code = " + swEdgeFlangeError2String(nStatus));
 
            bStatus = swFeature.ModifyDefinition(swEdgeFlangeData, swDocument, null);
            Debug.Print("Status of modify definition = " + bStatus);
 
            swEdgeFlangeData.AccessSelections(swDocument, null);
            vEdges = null;
            vEdges = (object[])swEdgeFlangeData.Edges;
            if (((vEdges != null)))
            {
                lNumEdges = vEdges.GetUpperBound(0) - vEdges.GetLowerBound(0) + 1;
                Debug.Print("Number of edges in edge flange = " + lNumEdges);
            }
            else
            {
                Debug.Print("Number of edges in edge flange = 0");
            }
 
            swEdgeFlangeData.ReleaseSelectionAccess();
        }
 
 
        private string swEdgeFlangeError2String(swEdgeFlangeError_e nStatus)
        {
            string functionReturnValue = null;
 
            switch ((nStatus))
            {
                case 0:
                    functionReturnValue = "no error";
                    break;
                case swEdgeFlangeError_e.swEdgeFlangeError_EdgeAlreadyExists:
                    functionReturnValue = "edge already exists";
                    break;
                case swEdgeFlangeError_e.swEdgeFlangeError_EdgeNotSpecified:
                    functionReturnValue = "edge not specified";
                    break;
                case swEdgeFlangeError_e.swEdgeFlangeError_NumberOfEdgesAndSketchesNotEqual:
                    functionReturnValue = "number mismatch";
                    break;
                case swEdgeFlangeError_e.swEdgeFlangeError_SketchNotSpecified:
                    functionReturnValue = "sketch not specified";
                    break;
                default:
                    functionReturnValue = "unknown error";
                    break;
            }
            return functionReturnValue;
 
        }
 
        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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Remove Edge from Edge Flange Feature Example (C#)
*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.