Hide Table of Contents

SOLIDWORKS API Help

Create Normal Cut Feature Example (C#)

This example shows how to create a normal cut feature.

//------------------------------------------------------------------------------
// Preconditions:
// 1. Open:
//    c:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2019\samples\whatsnew\sheet metal\normal_cut.sldprt.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Creates Normal Cut1 in the FeatureManager design tree.
// 2. Edits the feature by specifying a normal cut direction entity.
// 3. Inspect the Immediate window.
//
// NOTE: Because the model is used elsewhere, do not save any changes to it.
//------------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace CreateNormalCut_CSharp
{
    partial class SolidWorksMacro
    {
 
        private ModelDoc2 swModel;
        private ModelDocExtension swModelDocExt;
        private FeatureManager swFeatMgr;
        private Feature swFeat;
        private SMNormalCutFeatureData2 swNormalCutFeatData;
        private SMNormalCutGroupData grpData;
        private SelectionMgr swSelMgr;
        private Face2 swCutDirectionFace;
        private int errCode;
        private bool boolstatus;
        private object[] varGrpNames;
        private int i;
        private int j;
        private string Name;
        private Face2 Face;
 
 
        public void Main()
        {
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModelDocExt = swModel.Extension;
            swFeatMgr = swModel.FeatureManager;
            swNormalCutFeatData = (SMNormalCutFeatureData2)swFeatMgr.CreateDefinition((int)swFeatureNameID_e.swFmNormalCut);
            swNormalCutFeatData.AutoPropagation = true;
            swNormalCutFeatData.OptimizeGeometry = true;
            swNormalCutFeatData.NormalCutParameters = (int)swNormalCutParameters_e.swNormalCutExtent;
 
            // Select the face(s) to make normal
 
            boolstatus = swModel.Extension.SelectByRay(0.0471296104838217, 0.0142054003862171, -0.00668923799798904, -0.13322686545804, 0.182153484913837, 0.974202602261958, 0.000619874904830013, 2, true, 1, 0);
 
            grpData = (SMNormalCutGroupData)swNormalCutFeatData.CreateGroup(out errCode);
 
            // Create the normal cut feature
 
            swFeat = swFeatMgr.CreateFeature(swNormalCutFeatData);
 
            // Modify the normal cut feature
 
            swNormalCutFeatData = (SMNormalCutFeatureData2)swFeat.GetDefinition();
            swNormalCutFeatData.AccessSelections(swModel, null);
            varGrpNames = (object[])swNormalCutFeatData.GetGroupNames();
 
            for (i = 0; i <= varGrpNames.GetUpperBound(0); i++)
            {
                Name = (string)varGrpNames[i];
                Debug.Print("GroupName: " + Name);
                grpData = (SMNormalCutGroupData)swNormalCutFeatData.GetGroupByName(Name);
                object[] varFaces = (object[])grpData.Faces;
                for (j = 0; j <= varFaces.GetUpperBound(0); j++)
                {
                    Face = (Face2)varFaces[j];
                    Debug.Print("Face " + j + " area: " + Face.GetArea());
                }
                Debug.Print("--------------------");
            }
 
            //Specify the cut direction
 
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            boolstatus = swModel.Extension.SelectByRay(-0.149999999999892, 0.0258556514245498, -0.00463505465353364, 0.393242668518252, 0.12460738379391, -0.910951811876282, 0.00122626958447854, 2, false, 0, 0);
            swCutDirectionFace = null;
            swCutDirectionFace = (Face2)swSelMgr.GetSelectedObject6(1, -1);
 
            Entity swSelectEnt = (Entity)swCutDirectionFace;
            boolstatus = swSelectEnt.Select4(falsenull);
            swNormalCutFeatData.CutDirection = swCutDirectionFace;
 
            bool isModified = swFeat.ModifyDefinition(swNormalCutFeatData, swModel, null);
 
        }
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        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:   Create Normal Cut 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) 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.