IFeatureManager Interface 二

This example shows how to insert a Grid System feature into a model.

//-----------------------------------------------------------------------------
// Preconditions: 
// 1. Verify that the specified part template exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens a new part document.
// 2. Creates a sketch of a circle.
// 3. Inserts GridSystem1, which contains Surface-Extrude1, Level1, Level2,
//    and two derived sketches, in the FeatureManager design tree.
// 4. Sets the height of each level of the surface extrude to 50.0 mm.
// 5. Examine the Immediate window and graphics area.
// 6. Expand GridSystem1 in FeatureManager design tree.
//------------------------------------------------------------------------------ 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace InsertGridFeature_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        Feature GridFeature;
        ModelDoc2 Part;
        ModelView myModelView;
        SketchSegment skSegment;
        bool boolstatus;
        int longstatus;

        public void Main()
        {

            swApp.ResetUntitledCount(0, 0, 0);
            Part = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2016\\templates\\Part.prtdot", 0, 0, 0);
            swApp.ActivateDoc2("Part1", false, ref longstatus);
            Part = (ModelDoc2)swApp.ActiveDoc;

            myModelView = (ModelView)Part.ActiveView;
            myModelView.FrameLeft = 0;
            myModelView.FrameTop = 0;
            myModelView.FrameState = (int)swWindowState_e.swWindowMaximized;
            Part.ShowNamedView2("*Isometric", 7);

            skSegment = Part.SketchManager.CreateCircle(-0.019633, 0.076084, 0.0, -0.001997, 0.081475, 0.0);
            Part.SketchManager.InsertSketch(true);

            boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, 0);

            object offsetArray = null;
            double[] heightsArray = new double[2];
            heightsArray[0] = 0.05;
            heightsArray[1] = 0.05;
            offsetArray = heightsArray;

            GridFeature = Part.FeatureManager.InsertGridFeature((offsetArray));
            Debug.Print(GridFeature.Name + " was created.");

            Part.ViewZoomtofit();
        }

        public SldWorks swApp;

    }
} 
This example shows how to create a weldment gusset feature.

//----------------------------------------------------------------------------
// Preconditions: Open public_documents\samples\tutorial\api\weldment_box3.sldprt.
//
// Postconditions: 
// 1. Creates Gusset5.
// 2. Expand CutList(32) in the FeatureManager design tree and
//    scroll to the bottom of the list.
// 3. Examine the graphics area.
//
// NOTE: Because the model is used elsewhere, do not save changes.
// ---------------------------------------------------------------------------
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 InsertGusset_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        ModelDoc2 Part;
        Feature myFeature;
        bool boolstatus;

        public void Main()
        {
            Part = (ModelDoc2)swApp.ActiveDoc;

            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.600909534718824, 0.15614125327869, -0.985000000000127, true, 1, null, 0);
            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.597259667129663, 0.0149999999998727, -0.944257845206607, true, 1, null, 0);

            myFeature = Part.FeatureManager.InsertGussetFeature3(0.005, (int)swGussetThicknessType_e.swGussetThicknessBothSides, (int)swGussetProfileLocationType_e.swGussetProfileLocationCenter, false, 0.025, 0.025, 0.015, 0.78539816339745, 0.015, false,
            0.005, 0, false, false, false, 0.0125, 0.0125, 0.785398163397452, true, false);
        }


        public SldWorks swApp;

    }
}
This example shows how to create a multibody macro feature using a Visual C# SOLIDWORKS add-in.

//---------------------------------------------------------------------------- 
// Preconditions: 
//  1. Locate API: C#\VB.NET Add-ins to Create a Macro Feature in the SOLIDWORKS
//     API forum.
//  2. Click attachment, SwCSharpAddinMF.zip.
//  3. Download and unzip the file.
//  4. Open Visual Studio 2015 and convert the Visual C# solution in Visual Studio.
//  5. Modify the project references to point to your SOLIDWORKS primary
//     interop assemblies.
//  6. Right-click the project name in the Solution Explorer, click 
//     Add Reference, click Assemblies > Framework, click
//     Microsoft.VisualBasic, select its check box, click Microsoft.CSharp, select
/      its check box, and click OK.
//  7. Double-click SwAddin.cs in the Solution Explorer.
//  8. Replace region ISwComFeature Implementation with this.
//  9. Replace AddMacroFeature() with this.
// 10. Click Project > SwCSharpAddinMF Properties > Application and change 
//     Target framework to .NET FrameWork 4.
// 11. Add using Microsoft.VisualBasic; to the top of SwAddIn.cs. 
// 12. Click Build > Build Solution.
//     NOTE: The Output window notifies that types registered successfully.
//     If that message does not appear in the Output window, repeat from
//     step 1.
// 13. Open SOLIDWORKS.
// 14. Open public_documents\samples\tutorial\multibody\multi_local.sldprt.
//
// Postconditions: 
//  1. Click OK in each message box. 
//  2. Displays C# Addin on the Tools menu. 
//  3. Fires the ISldWorks_ActiveDocChangeNotify event and inserts 
//     the macro feature, MacroFeature1, in the FeatureManager design tree, 
//     which:
//     * Consumes the part's solid bodies, Fillet5 and Fillet6.
//     * Creates two solid bodies, MacroFeature1[1] and MacroFeature1[2].
//  4. Examine the graphics area and FeatureManager design tree.
//
// NOTE: Because the model is used elsewhere, do not save changes. 
//----------------------------------------------------------------------------

//Region ISwComFeature Implementation

#region "ISwComFeature Implementation"
 
        public object Edit(object app, object modelDoc, object feature)
        {
            Interaction.MsgBox("Macro feature edit");
            return null;
        }
 
        public object Regenerate(object app, object modelDoc, object feature)
        {
            object functionReturnValue = null;
            Collection OutputBodies = new Collection();
            Body2 swBody = default(Body2);
            Body2[] swBodies = null;
            MacroFeatureData swMacroFeatData = default(MacroFeatureData);
            swMacroFeatData = (MacroFeatureData)((Feature)feature).GetDefinition();
            swMacroFeatData.EnableMultiBodyConsume = true;
 
            Modeler swModeler = default(Modeler);
            swModeler = (Modeler)((SldWorks)app).GetModeler();
            double[] dblData = new double[9];
            dblData[0] = 0;
            dblData[1] = 0;
            dblData[2] = 0;
            dblData[3] = 1;
            dblData[4] = 0;
            dblData[5] = 0;
            dblData[6] = 0.1;
            dblData[7] = 0.1;
            dblData[8] = 0.1;
 
            //Output body 1
            swBody = swModeler.CreateBodyFromBox3(dblData);
            OutputBodies.Add(swBody);
 
            //Output body 2
            dblData[1] = 0.15;
            swBody = swModeler.CreateBodyFromBox3(dblData);
            OutputBodies.Add(swBody);
 
            int i = 0;
            int j = 0;
            object[] vFaces = null;
            object[] vEdges = null;
 
            for (i = 1; i <= OutputBodies.Count; i++)
            {
                swBody = (Body2)OutputBodies[i];
                vEdges = (object[])swBody.GetEdges();
                vFaces = (object[])swBody.GetFaces();
 
                for (j = 0; j <= Information.UBound(vEdges); j++)
                {
                    swMacroFeatData.SetEdgeUserId((Edge)vEdges[j], j, 0);
                }
                for (j = 0; j <= Information.UBound(vFaces); j++)
                {
                    swMacroFeatData.SetFaceUserId((Face2)vFaces[j], j, 0);
                }
 
                swBodies[i - 1] = (Body2)OutputBodies[i];
            }
 
            functionReturnValue = swBodies;
            Interaction.MsgBox("Macro feature rebuild");
            return functionReturnValue;
 
        }
 
        public object Security(object app, object modelDoc, object feature)
        {
            Interaction.MsgBox("Macro feature security");
            return null;
        }
 
        #endregion

Back to top

//AddMacroFeature

      public bool AddMacroFeature()
      {
 
            ModelDoc2 moddoc = default(ModelDoc2);
            FeatureManager FeatMgr = default(FeatureManager);
            Feature MacroFeature = default(Feature);
 
            moddoc = (ModelDoc2)this.iSwApp.ActiveDoc;
            FeatMgr = moddoc.FeatureManager;
 
            //Collect input bodies
            object vBodies = null;
            vBodies = ((PartDoc)moddoc).GetBodies2((int)swBodyType_e.swAllBodies, false);
 
            //Create the macro feature
 MacroFeature = FeatMgr.InsertMacroFeature3("MacroFeature", "SwVBAddinTest.SwAddin", null, null, null, null, null, null, vBodies, null,
            (int)swMacroFeatureOptions_e.swMacroFeatureByDefault);

 
            return true;
       }
This example shows how to insert and edit a mate reference.

//----------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified part to open exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens the part.
// 2. Adds a mate reference.
// 3. Edits the mate reference.
// 4. Expand MateReferences in the FeatureManager design tree
//    and click MyDefault<1>.
// 5. Examine the graphics area and Immediate window.
//
// NOTE: Because the part is used elsewhere, do not save changes.
//----------------------------------------------------------------
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            Feature swFeature = default(Feature);
            FeatureManager swFeatureMgr = default(FeatureManager);
            SelectionMgr swSelectionMgr = default(SelectionMgr);
            Entity swPlane = default(Entity);
            Face2 swFace = default(Face2);
            Entity swFaceEntity = default(Entity);
            MateReference swMateReference = default(MateReference);
            string fileName = null;
            bool status = false;
            int errors = 0;
            int warnings = 0;
 
            fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\fillets\\knob.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
 
            //Insert mate reference
            status = swModelDocExt.SelectByID2("Front", "PLANE", 0, 0, 0, true, 1, null, 0);
            swSelectionMgr = (SelectionMgr)swModel.SelectionManager;
            swPlane = (Entity)swSelectionMgr.GetSelectedObject6(1, -1);
            status = swModelDocExt.SelectByID2("", "FACE", 0.00835786916030656, 0.00429540237419701, 0, true, 2, null, 0);
            swFeatureMgr = (FeatureManager)swModel.FeatureManager;
            swFeature = (Feature)swFeatureMgr.InsertMateReference2("Default", null, 0, 1, false, null, 0, 2, false, null,
            0, 0);
            swModel.ClearSelection2(true);
 
            //Edit mate reference 
            status = swModelDocExt.SelectByID2("", "FACE", 0.0117890806857872, 0.00419179196288511, 0.00999999999999091, false, 0, null, 0);
            swFace = (Face2)swSelectionMgr.GetSelectedObject6(1, -1);
            swFaceEntity = (Entity)swFace;
            status = swModelDocExt.SelectByID2("Default-<1>", "POSGROUP", 0, 0, 0, false, 0, null, 0);
            swFeature = (Feature)swSelectionMgr.GetSelectedObject6(1, -1);
            swMateReference = (MateReference)swFeature.GetSpecificFeature2();
            swModel.ClearSelection2(true);
            status = swMateReference.Edit("MyDefault", swPlane, (int)swMateReferenceType_e.swMateReferenceType_default, (int)swMateReferenceAlignment_e.swMateReferenceAlignment_Any, swFaceEntity, (int)swMateReferenceType_e.swMateReferenceType_default, (int)swMateReferenceAlignment_e.swMateReferenceAlignment_Any, null, (int)swMateReferenceType_e.swMateReferenceType_default, (int)swMateReferenceAlignment_e.swMateReferenceAlignment_Any);
            Debug.Print("Mate reference modified and replaced? " + status);
 
            swModel.EditRebuild3();
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to get data for a mirror pattern feature.

//--------------------------------------------------------------------
// Postconditions:
// 1. Verify that the specified part document to open exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens the specified part document.
// 2. Creates Boss-Extrude2.
// 3. Mirrors Boss-Extrude2 to create LPattern1.
// 4. Mirrors Boss-Extrude1 and LPattern1 to create Mirror1.
// 5. Gets the patterned features of Mirror1.
// 6. Examine the FeatureManager design tree, the graphics area, and
//    the Immediate window.
//
// NOTE: Because the part is used elsewhere, do not save changes.
//--------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace MirrorPatternFeatureDataCSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SketchSegment swSketchSegment = default(SketchSegment);
            SketchManager swSketchManager = default(SketchManager);
            Feature swFeature = default(Feature);
            FeatureManager swFeatureManager = default(FeatureManager);
            MirrorPatternFeatureData swMirrorPatternFeatureData = default(MirrorPatternFeatureData);
            Entity swEntity = default(Entity);
            Face2 swFace = default(Face2);
            SelectData swSelData = null;
            bool status = false;
            string fileName = null;
            int errors = 0;
            int warnings = 0;
            object[] faceArray = null;
            object[] patternArray = null;
            int i = 0;
 
            fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\beam with holes.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
 
            //Create Boss-Extrude2
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByID2("", "FACE", 0.0919322519657158, -0.0190749842767559, 0.0399999999999068, false, 0, null, 0);
            swSketchManager = (SketchManager)swModel.SketchManager;
            swSketchSegment = (SketchSegment)swSketchManager.CreateCircle(0.092035, -0.020145, 0.0, 0.093952, -0.029594, 0.0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Arc1", "SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
            swFeature = (Feature)swFeatureManager.FeatureExtrusion3(true, false, false, 0, 0, 0.01, 0.01, false, false, false,
            false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, true, true, true,
            0, 0, false);
 
            //Create LPattern1
            status = swModelDocExt.SelectByID2("Boss-Extrude2", "BODYFEATURE", 0, 0, 0, false, 4, null, 0);
            status = swModelDocExt.SelectByID2("", "EDGE", 0.0441545689173921, -0.0398591118729428, 0.0402307394506352, true, 1, null, 0);
            swFeature = (Feature)swFeatureManager.FeatureLinearPattern4(3, 0.04, 1, 0.01, false, false, "NULL", "NULL", false, false,
            false, false, false, false, true, true, false, false, 0, 0);
 
            //Create Mirror1
            status = swModelDocExt.SelectByID2("Boss-Extrude1", "BODYFEATURE", 0, 0, 0, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("", "FACE", 0.232539736404746, -0.0399999999999068, 0.0224388980993808, true, 0, null, 0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("LPattern1", "BODYFEATURE", 0, 0, 0, false, 1, null, 0);
            status = swModelDocExt.SelectByID2("Boss-Extrude1", "BODYFEATURE", 0, 0, 0, true, 1, null, 0);
            status = swModelDocExt.SelectByID2("", "FACE", 0.232539736404746, -0.0399999999999068, 0.0224388980993808, true, 2, null, 0);
            swFeature = (Feature)swFeatureManager.InsertMirrorFeature2(false, false, false, false, (int)swFeatureScope_e.swFeatureScope_AllBodies);
 
            //Get Mirror1 properties
            swMirrorPatternFeatureData = (MirrorPatternFeatureData)swFeature.GetDefinition();
            Debug.Print("  " + swFeature.Name);
            Debug.Print("    Geometry pattern                                     = " + swMirrorPatternFeatureData.GeometryPattern);
            Debug.Print("    Number of mirrored faces                             = " + swMirrorPatternFeatureData.GetMirrorFaceCount());
            Debug.Print("    Type of mirrored plane (0 = face; 1 = plane)         = " + swMirrorPatternFeatureData.GetMirrorPlaneType());
            Debug.Print("    Number of patterned features                         = " + swMirrorPatternFeatureData.GetPatternFeatureCount());
 
            //Roll back to get to the faces and features
            status = swMirrorPatternFeatureData.AccessSelections(swModel, null);
            swModel.ClearSelection2(true);
 
            if (1 == swMirrorPatternFeatureData.GetMirrorPlaneType())
            {
                swFeature = (Feature)swMirrorPatternFeatureData.Plane;
                //Cannot select a reference plane through Entity, so
                //use Feature
                Debug.Print("    Plane                  = " + swFeature.Name);
                status = swFeature.Select2(true, 0);
            }
            else
            {
                //Select face through Entity
                swEntity = (Entity)swMirrorPatternFeatureData.Plane;
                status = swEntity.Select4(true, swSelData);
            }
 
            faceArray = (object[])swMirrorPatternFeatureData.MirrorFaceArray;
            if ((faceArray != null))
            {
                swModel.ClearSelection2(true);
                status = false;
                for (i = 0; i < faceArray.Length; i++)
                {
                    swFace = (Face2)faceArray[i];
                    swEntity = (Entity)swFace;
                    status = swEntity.Select4(true, swSelData);
                }
            }
 
            patternArray = (object[])swMirrorPatternFeatureData.PatternFeatureArray;
            if ((patternArray != null))
            {
                swModel.ClearSelection2(true);
                status = false;
                for (i = 0; i < patternArray.Length; i++)
                {
                    swFeature = (Feature)patternArray[i];
                    Debug.Print("    Feature (" + i + ")                                          = " + swFeature.Name);
                    status = swFeature.Select2(true, 0);
                }
            }
            //Cancel changes
            swMirrorPatternFeatureData.ReleaseSelectionAccess();
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to move all of the bodies in a part document.

//-------------------------------------------------------------
// Preconditions:
// 1. Specified part document to open exists.
// 2. Run the macro.
//
// Postconditions: All of the bodies in the part document
// are moved to the specified location.
//
// NOTE: Because this part is used elsewhere, do not save
// any changes when closing it.
//--------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
 
namespace MoveBodiesCSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
        public void SelectBodies(SldWorks swApp, ModelDoc2 swModel, object[] bodyArr)
        {
            // Select and mark the bodies to move
            SelectionMgr swSelMgr = default(SelectionMgr);
            SelectData swSelData = default(SelectData);
            Body2 swBody = default(Body2);
            bool status = false;
            int i = 0;
 
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            swSelData = (SelectData)swSelMgr.CreateSelectData();
 
            if ((bodyArr == null))
                return;
            for (i = 0; i <= bodyArr.GetUpperBound(0); i++)
            {
 
                swBody = (Body2)bodyArr[i];
                swSelData.Mark = 1;
                status = swBody.Select2(true, swSelData);
            }
 
        }
 
        public void Main()
        {
 
            ModelDoc2 swModel = default(ModelDoc2);
            PartDoc swPart = default(PartDoc);
            object[] bodyArr = null;
            FeatureManager swFeatMgr = default(FeatureManager);
            Feature swFeat = default(Feature);
            string fileName = null;
            int errors = 0;
            int warnings = 0;
 
            fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\multibody\\multi_inter.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swPart = (PartDoc)swModel;
            swFeatMgr = (FeatureManager)swModel.FeatureManager;
 
            swModel.ClearSelection2(true);
 
            // Get the bodies to move
            bodyArr = (object[])swPart.GetBodies2((int)swBodyType_e.swAllBodies, false);
            SelectBodies(swApp, swModel, bodyArr);
 
            // Move the bodies
            swFeat = (Feature)swFeatMgr.InsertMoveCopyBody2(0.1, 0.2, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            false, 1);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to create a Move Face feature by translating a face on a part.

//---------------------------------------------------------------------------
// Preconditions: Verify that the specified part exists.
//
// Postconditions: 
// 1. Creates Move Face1 in the FeatureManager design tree.
// 2. Modifies the translation parameters of Move Face1. 
//
// NOTE: Because the part is used elsewhere, do not save any changes.
//---------------------------------------------------------------------------
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 InsertMoveFace3_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 swModel;
        ModelDocExtension swModelDocExt;
        FeatureManager swFeatMgr;
        Feature swFeat;
        MoveFaceFeatureData swMoveFaceFeat;
        object transParams;
        bool boolstatus;
        double[] triadParams = new double[3];
        int fileerror;
 
        int filewarning;
 
        public void Main()
        {
            // Open the SOLIDWORKS document
            swApp.OpenDoc6("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\assemblymates\\knee.sldprt", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref fileerror, ref filewarning);
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModelDocExt = swModel.Extension;
            swFeatMgr = swModel.FeatureManager;
 
            // Translation parameters
            triadParams[0] = 0;
            triadParams[1] = 0.05;
            triadParams[2] = 0;
 
            transParams = triadParams;
 
            // Select face to move
            boolstatus = swModel.Extension.SelectByID2("", "FACE", 0.04239074672171, 0.01587499999999, 0.3283508339712, false, 1, null, 0);
 
            // Create the Move Face feature by
            // translating the selected face
            swFeat = (Feature)swFeatMgr.InsertMoveFace3((int)swMoveFaceType_e.swMoveFaceTypeTranslate, false, 0, 0, (transParams), null, (int)swEndConditions_e.swEndCondBlind, 0);
 
            // Modify the Move Face feature
            swMoveFaceFeat = (MoveFaceFeatureData)swFeat.GetDefinition();
 
            // Roll back the Move Face feature
            swMoveFaceFeat.AccessSelections(swModel, null);
 
            triadParams[0] = 0;
            triadParams[1] = 0.1;
            triadParams[2] = 0;
 
            transParams = triadParams;
 
            swMoveFaceFeat.TriadTranslationParameters = (transParams);
 
            // Roll back the part with the modified Move Face feature
            swFeat.ModifyDefinition(swMoveFaceFeat, swModel, null);
 
        }
 
        public SldWorks swApp;
 
    }
}
This example shows how to insert a solid body boundary surface feature.

//-------------------------------------------------------------
// Preconditions: Verify that the specified part template
// exists.
//
// Postconditions:
// 1. Opens a new part.
// 2. Inserts a sketch of a rectangle, Sketch1, on Front Plane.
// 3. Creates Surface-Plane1 using Sketch1.
// 4. Creates Plane1.
// 5. Creates a sketch of a circle, Sketch2, on Plane1.
// 6. Creates Surface-Plane2 using Sketch2.
// 7. Inserts a solid body boundary surface feature, Boundary-Surface1,
//    using Surface-Plane1 and Surface-Plane2.
// 8. Examine the graphics area and expand Solid Bodies(1) in the
//    FeatureManager design tree to verify step 7.
//--------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            FeatureManager swFeatureMgr = default(FeatureManager);
            SketchManager swSketchMgr = default(SketchManager);
            RefPlane swRefPlane = default(RefPlane);
            SketchSegment swSketchSegment = default(SketchSegment);
            Feature swFeature = default(Feature);
            object[] sketchSegments = null;
            bool status = false;
 
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2016\\templates\\part.prtdot", 0, 0, 0);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            swSketchMgr = (SketchManager)swModel.SketchManager;
            swFeatureMgr = (FeatureManager)swModel.FeatureManager;
 
            //Create Surface-Plane1
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", -0.0687189668956523, 0.0593633502290038, 0.00936526409663904, false, 0, null, 0);
            status = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstToRectEntity, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, false);
            status = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, true);
            sketchSegments = (object[])swSketchMgr.CreateCornerRectangle(-0.0399911197344551, 0.02969400507229, 0, 0.0502882343966202, -0.0299334728551311, 0);
            swSketchMgr.InsertSketch(true);
            status = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, true, 0, null, 0);
            status = swModel.InsertPlanarRefSurface();
            swModel.ClearSelection2(true);
 
            //Create Plane1
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
            swRefPlane = (RefPlane)swFeatureMgr.InsertRefPlane((int)swRefPlaneReferenceConstraints_e.swRefPlaneReferenceConstraint_Distance, 0.15, 0, 0, 0, 0);
            swModel.ClearSelection2(true);
 
            //Create Surface-Plane2
            status = swModelDocExt.SelectByID2("Plane1", "PLANE", 0, 0, 0, true, 0, null, 0);
            swSketchSegment = (SketchSegment)swSketchMgr.CreateCircle(0.003592, 0.003353, 0.0, 0.035202, -0.057233, 0.0);
            swSketchMgr.InsertSketch(true);
            status = swModelDocExt.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, false, 1, null, 0);
            status = swModel.InsertPlanarRefSurface();
            swModel.ClearSelection2(true);
            swModel.ViewZoomtofit2();
 
            //Insert a solid body boundary surface feature
            status = swModelDocExt.SelectByID2("Surface-Plane1", "SURFACEBODY", -0.0399911197344551, 0.02969400507229, 0, false, 8193, null, 0);
            status = swModelDocExt.SelectByID2("Surface-Plane2", "SURFACEBODY", -0.0463651179854531, -0.0432741101197696, 0.15, true, 16385, null, 0);
            swFeature = (Feature)swFeatureMgr.SetNetBlendCurveData(0, 0, (int)swTangencyType_e.swTangencyNone, 0, 1, true);
            swFeature = (Feature)swFeatureMgr.SetNetBlendCurveData(0, 1, (int)swTangencyType_e.swTangencyNone, 0, 1, true);
            swFeature = (Feature)swFeatureMgr.SetNetBlendDirectionData(0, 32, 0, false, false);
            swFeature = (Feature)swFeatureMgr.SetNetBlendDirectionData(1, 32, 0, false, false);
            swFeature = (Feature)swFeatureMgr.InsertNetBlend2(2, 2, 0, false, 0.0001, false, true, true, true, false,
            -1, -1, false, -1, false, false, -1, false, -1, true,
            true);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to create a loft using profiles, guide curves, and a centerline.

//---------------------------------------------------------------
// Preconditions: Verify that the specified part template exists.
//
// Postconditions:
// 1. Creates a new part.
// 2. Creates a profile sketch.
// 3. Creates a reference plane and another profile sketch on that
//    reference plane.
// 4. Creates five curves: four guide curves and one centerline.
// 5. Selects the profile sketches, four guide curves, and the 
//    centerline.
// 6. Creates a loft feature.
// 7. Examine the FeatureManager design tree and graphics area.
//---------------------------------------------------------------
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SketchSegment swSketchSegment = default(SketchSegment);
            SketchManager swSketchManager = default(SketchManager);
            RefPlane swRefPlane = default(RefPlane);
            FeatureManager swFeatureManager = default(FeatureManager);
            bool status = false;
 
            //Create new part
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2016\\templates\\Part.prtdot", 0, 0, 0);
 
            //Create profile sketch
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.ClearSelection2(true);
            swSketchManager = (SketchManager)swModel.SketchManager;
            swSketchSegment = (SketchSegment)swSketchManager.CreateEllipse(0, 0, 0, 0.0706113079019074, 0, 0, 0, 0.0374944141689373, 0);
            swModel.ClearSelection2(true);
            swSketchManager.InsertSketch(true);
 
            // Create reference plane and another profile sketch
            // on that reference plane
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
            swRefPlane = (RefPlane)swFeatureManager.InsertRefPlane(8, 0.07, 0, 0, 0, 0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Plane1", "PLANE", 0, 0, 0, false, 0, null, 0);
            swSketchSegment = (SketchSegment)swSketchManager.CreateEllipse(0, 0, 0, 0.0527205722070845, 0, 0, 0, 0.0154164850136235, 0);
            swModel.ClearSelection2(true);
            swSketchManager.InsertSketch(true);
 
            // Create guide curves
            status = swModelDocExt.SelectByID2("Point4@Sketch1", "EXTSKETCHPOINT", 0, 0.0374944141689373, 0, false, 1, null, 0);
            status = swModelDocExt.SelectByID2("Point4@Sketch2", "EXTSKETCHPOINT", 0, 0.0154164850136235, 0, true, 1, null, 0);
            swModel.Insert3DSplineCurve(false);
 
            status = swModelDocExt.SelectByID2("Point5@Sketch2", "EXTSKETCHPOINT", -0.0527205722070845, 0, 0, true, 1, null, 0);
            status = swModelDocExt.SelectByID2("Point5@Sketch1", "EXTSKETCHPOINT", -0.0706113079019074, 0, 0, true, 1, null, 0);
            swModel.Insert3DSplineCurve(false);
 
            status = swModelDocExt.SelectByID2("Point6@Sketch2", "EXTSKETCHPOINT", 0, -0.0154164850136235, 0, true, 1, null, 0);
            status = swModelDocExt.SelectByID2("Point6@Sketch1", "EXTSKETCHPOINT", 0, -0.0374944141689373, 0, true, 1, null, 0);
            swModel.Insert3DSplineCurve(false);
 
            status = swModelDocExt.SelectByID2("Point3@Sketch2", "EXTSKETCHPOINT", 0.0527205722070845, 0, 0, true, 1, null, 0);
            status = swModelDocExt.SelectByID2("Point3@Sketch1", "EXTSKETCHPOINT", 0.0706113079019074, 0, 0, true, 1, null, 0);
            swModel.Insert3DSplineCurve(false);
 
            // Create centerline
            status = swModelDocExt.SelectByID2("Point2@Sketch2", "EXTSKETCHPOINT", 0, 0, 0, true, 1, null, 0);
            status = swModelDocExt.SelectByID2("Point2@Sketch1", "EXTSKETCHPOINT", 0, 0, 0, true, 1, null, 0);
            swModel.Insert3DSplineCurve(false);
 
            // Create loft
            status = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0.0706113079019074, 0, 0, false, 1, null, 0);
            status = swModelDocExt.SelectByID2("Sketch2", "SKETCH", 0.0527205722070845, 0, 0.07, true, 1, null, 0);
            status = swModelDocExt.SelectByID2("Curve1", "REFERENCECURVES", 0.0999754519565386, 0.0447609702560072, 0.128010464418594, true, 4098, null, 0);
            status = swModelDocExt.SelectByID2("Curve2", "REFERENCECURVES", 0.037643674311596, 0.0221603475855119, 0.115437869126538, true, 8194, null, 0);
            status = swModelDocExt.SelectByID2("Curve3", "REFERENCECURVES", 0.0999909384372586, -0.000744308680111772, 0.131301605626447, true, 12290, null, 0);
            status = swModelDocExt.SelectByID2("Curve4", "REFERENCECURVES", 0.158600974878482, 0.0218780932746938, 0.129235804629445, true, 16386, null, 0);
            status = swModelDocExt.SelectByID2("Curve5", "REFERENCECURVES", 0.0998735089003162, 0.022159545044488, 0.108064927518626, true, 4, null, 0);
            swFeatureManager.InsertProtrusionBlend(false, true, false, 1, 0, 0, 1, 1, true, true,
            false, 0, 0, 0, true, true, true);
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to insert a fill-surface feature.

//-------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified part template exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Sketches a circle on the Front Plane.
// 2. Offsets the Front Plane to create Plane1.
// 3. Sketches a circle on Plane1.
// 4. Creates a thin-feature loft using the circles
//    created in steps 1 and 3.
// 5. Selects one of the sketches to use for
//    the fill-surface feature.
// 6. Creates a fill-surface feature named Surface-Fill1.
// 7. Gets, sets, and prints some properties of the fill-surface feature
//    to the Immediate window.
// 8. Examine the FeatureManager design, graphics area, and the
//    the Immediate window.
//--------------------------------------------------------------
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace InsertFillFeature2CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SelectionMgr swSelMgr = default(SelectionMgr);
            SketchManager swSketchMgr = default(SketchManager);
            SketchSegment swSketchSegment = default(SketchSegment);
            FeatureManager swFeatMgr = default(FeatureManager);
            RefPlane swRefPlane = default(RefPlane);
            Feature swFeat = default(Feature);
            FillSurfaceFeatureData swFillSurfaceFeatureData = default(FillSurfaceFeatureData);
            object selObj = null;
            bool status = false;
            int nbrPatchEntities = 0;
            object[] patchEntities = null;
            object entTypes = null;
            int[] entTypesArray;
            int i = 0;
 
            //Open a new model document
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SolidWorks 2015\\templates\\part.prtdot", (int)swDwgPaperSizes_e.swDwgPaperAsize, 0, 0);
 
            //Select the front plane and sketch a circle
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            swModel.ClearSelection2(true);
            swSketchMgr = (SketchManager)swModel.SketchManager;
            swSketchSegment = (SketchSegment)swSketchMgr.CreateCircle(0.0, 0.0, 0.0, 0.018863, -0.048015, 0.0);
            swModel.ClearSelection2(true);
            swSketchMgr.InsertSketch(true);
 
            //Offset the front plane to create Plane1
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
            swFeatMgr = (FeatureManager)swModel.FeatureManager;
            swRefPlane = (RefPlane)swFeatMgr.InsertRefPlane(8, 0.0762, 0, 0, 0, 0);
            status = swModelDocExt.SelectByID2("Plane1", "PLANE", 0, 0, 0, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            swSketchSegment = (SketchSegment)swSketchMgr.CreateCircle(0.0, 0.0, 0.0, 0.005144, -0.017148, 0.0);
            swModel.ClearSelection2(true);
            swSketchMgr.InsertSketch(true);
 
            //Create a loft as a thin feature
            status = swModelDocExt.SelectByID2("Sketch2", "SKETCH", -0.0120997659765269, 0.0131954647737917, 0, false, 1, null, 0);
            status = swModelDocExt.SelectByID2("Sketch1", "SKETCH", -0.0137458916138411, 0.0497220981864567, 0, true, 1, null, 0);
            swFeatMgr.InsertProtrusionBlend(false, true, false, 1, 0, 0, 1, 1, true, true,
            true, 0.000254, 0.000254, 0, true, true, true);
 
            //Get the sketch for the fill-surface feature
            status = swModelDocExt.SelectByID2("Sketch2", "SKETCH", -0.0309259362651374, -0.0150632202505945, 0.0265529245975468, true, 257, null, (int)swSelectOption_e.swSelectOptionDefault);
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            selObj = (object)swSelMgr.GetSelectedObject6(1, 257);
 
            //Insert the fill-surface feature
            swFeat = (Feature)swFeatMgr.InsertFillSurface2(2, (int)swFeatureFillSurfaceOptions_e.swOptimizeSurface, selObj, (int)swContactType_e.swContact, null, null);
 
            //Access the fill-surface feature
            swFillSurfaceFeatureData = (FillSurfaceFeatureData)swFeat.GetDefinition();
            status = swFillSurfaceFeatureData.AccessSelections(swModel, null);
            Debug.Print("Fill-surface feature: ");
            Debug.Print("  Number of constraint curves: " + swFillSurfaceFeatureData.GetConstraintCurvesCount());
            nbrPatchEntities = swFillSurfaceFeatureData.GetPatchBoundaryCount();
            Debug.Print("  Number of entities used to define the patch boundary: " + nbrPatchEntities);
            if (nbrPatchEntities > 0)
            {
                //Get the type of patch boundary entities
                patchEntities = (object[])swFillSurfaceFeatureData.GetPatchBoundary(out entTypes);
                entTypesArray = (int[])entTypes;
                for (i = 0; i <= nbrPatchEntities - 1; i++)
                {
                    Debug.Print("  Type of entity for patch boundary " + (i + 1) + " (1 = edge; 9 = sketch) : " + entTypesArray[i]);
                }
                Debug.Print("  Results merged? " + swFillSurfaceFeatureData.Merge);
                swFillSurfaceFeatureData.OptimizeSurface = false;
                Debug.Print("  Patch optimized? " + swFillSurfaceFeatureData.OptimizeSurface);
                Debug.Print("  Original resolution control: " + swFillSurfaceFeatureData.ResolutionControl);
                if (swFillSurfaceFeatureData.OptimizeSurface == false)
                {
                    swFillSurfaceFeatureData.ResolutionControl = 1;
                }
                Debug.Print("  Updated resolution control (valid values 1, 2 and 3; setting this value only valid if patch is not optimized): " + swFillSurfaceFeatureData.ResolutionControl);
            }
            status = swFeat.ModifyDefinition(swFillSurfaceFeatureData, swModel, null);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to select multiple splines for the guide curves for a loft feature.

//---------------------------------------------------------------
// Preconditions: Verify that the specified part template exists.
//
// Postconditions:
// 1. Creates a new part.
// 2. Creates a profile sketch.
// 3. Creates a reference plane and another profile sketch on that
//    reference plane.
// 4. Creates two splines for the guide curves.
// 5. Selects the profile sketches.
// 6. Selects the splines and groups them as an object.
// 7. Creates a loft feature.
// 8. Examine the FeatureManager design tree and graphics area.
//---------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SketchSegment swSketchSegment = default(SketchSegment);
            SketchManager swSketchManager = default(SketchManager);
            RefPlane swRefPlane = default(RefPlane);
            FeatureManager swFeatureManager = default(FeatureManager);
            bool status = false;
 
            //Create a new part
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2017\\templates\\Part.prtdot", 0, 0, 0);
 
            //Create a profile sketch
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.ClearSelection2(true);
            swSketchManager = (SketchManager)swModel.SketchManager;
            swSketchSegment = (SketchSegment)swSketchManager.CreateEllipse(0, 0, 0, 0.0706113079019074, 0, 0, 0, 0.0374944141689373, 0);
            swModel.ClearSelection2(true);
            swSketchManager.InsertSketch(true);
 
            //Create a reference plane and another profile sketch
            //on that reference plane
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
            swRefPlane = (RefPlane)swFeatureManager.InsertRefPlane(8, 0.07, 0, 0, 0, 0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Plane1", "PLANE", 0, 0, 0, false, 0, null, 0);
            swSketchSegment = (SketchSegment)swSketchManager.CreateEllipse(0, 0, 0, 0.0527205722070845, 0, 0, 0, 0.0154164850136235, 0);
            swModel.ClearSelection2(true);
            swSketchManager.InsertSketch(true);
 
            //Create a spline
            status = swModelDocExt.SelectByID2("Right Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            object pointArray = null;
            double[] points = new double[15];
            points[0] = -0.07;
            points[1] = 0.0154164850136235;
            points[2] = 0;
            points[3] = -0.0531092941649547;
            points[4] = 0.0280386111480766;
            points[5] = 0;
            points[6] = -0.0296934467839947;
            points[7] = 0.0229795168190776;
            points[8] = 0;
            points[9] = -0.0112921067380967;
            points[10] = 0.026354325474415;
            points[11] = 0;
            points[12] = 0;
            points[13] = 0.0374944141689373;
            points[14] = 0;
            pointArray = points;
            swSketchSegment = (SketchSegment)swSketchManager.CreateSpline((pointArray));
            swSketchManager.InsertSketch(true);
            swModel.ClearSelection2(true);
 
            //Create another spline
            status = swModelDocExt.SelectByID2("Right Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            points = new double[9];
            points[0] = -0.07;
            points[1] = -0.0154164850136235;
            points[2] = 0;
            points[3] = -0.0307689275649068;
            points[4] = -0.0233694015292372;
            points[5] = 0;
            points[6] = 0;
            points[7] = -0.0374944141689373;
            points[8] = 0;
            pointArray = points;
            swSketchSegment = swSketchManager.CreateSpline((pointArray));
            swSketchManager.InsertSketch(true);
            swModel.ClearSelection2(true);
 
            //Select the profile sketches
            status = swModelDocExt.SelectByID2("Sketch1", "SKETCH", -0.0585496337278505, 0.0209585732143712, 1, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("Sketch2", "SKETCH", -0.0379093739088495, 0.0107136192740755, 1, true, 0, null, 0);
 
            //Select the splines for the guide curves
            status = swModelDocExt.SelectByID2("Spline1@Sketch3", "EXTSKETCHSEGMENT", -0.00620659823337474, 0.0304187689522769, 2, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("Spline1@Sketch4", "EXTSKETCHSEGMENT", -0.0402947949143199, -0.0206106896601265, 2, true, 0, null, 0);
            //Group the selected splines as an object
            status = swModelDocExt.SelectByID2("Unknown", "SELOBJGROUP", 0, 0, 0, true, 2, null, 0);
 
            //Create a loft
            swFeatureManager.InsertProtrusionBlend2(false, true, false, 1, 0, 0, 1, 1, true, true,
            false, 0, 0, 0, true, true, true, 0); 
 
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to create a constraint-based angle reference plane.

//-----------------------------------------------------------
// 1. Verify that the specified part exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Creates a constraint-based reference plane.
// 2. Examine the Immediate window.
//
// NOTE: Because the part is used elsewhere, do not
// save changes.
//-----------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace InsertRefPlaneFeatureManagerCSharp.csproj

{

    public partial class SolidWorksMacro

    {

        public void Main()

        {

            ModelDoc2 swModel = default(ModelDoc2);

            ModelDocExtension swModelDocExt = default(ModelDocExtension);

            FeatureManager swFeatureManager = default(FeatureManager);

            Feature swFeature = default(Feature);

            RefPlane swRefPlane = default(RefPlane);

            SelectionMgr swSelMgr = default(SelectionMgr);

            RefPlaneFeatureData swRefPlaneFeatureData = default(RefPlaneFeatureData);

            int fileerror = 0;

            int filewarning = 0;

            bool boolstatus = false;

            int planeType = 0;

 

            swApp.OpenDoc6("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\plate.sldprt", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref fileerror, ref filewarning);

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swModelDocExt = (ModelDocExtension)swModel.Extension;

            swFeatureManager = (FeatureManager)swModel.FeatureManager;

            swSelMgr = (SelectionMgr)swModel.SelectionManager;

 

            // Create a constraint-based reference plane 

            boolstatus = swModelDocExt.SelectByID2("", "FACE", 0.028424218552, 0.07057725774359, 0, true, 0, null, 0);

            boolstatus = swModelDocExt.SelectByID2("", "EDGE", 0.05976462601598, 0.0718389621656, 0.0001242036435087, true, 1, null, 0);

            swRefPlane = (RefPlane)swFeatureManager.InsertRefPlane(16, 0.7853981633975, 4, 0, 0, 0);

 

            // Get type of the just-created reference plane 

            boolstatus = swModelDocExt.SelectByID2("Plane1", "PLANE", 0, 0, 0, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);

            swFeature = (Feature)swSelMgr.GetSelectedObject6(1, -1);

            swRefPlaneFeatureData = (RefPlaneFeatureData)swFeature.GetDefinition();

 

            planeType = swRefPlaneFeatureData.Type2;

            Debug.Print("Type of reference plane using IRefPlaneFeatureData::Type2: ");

            switch (planeType)

            {

                case 0:

                    Debug.Print(" Invalid");

                    break;

                case 1:

                    Debug.Print(" Undefined");

                    break;

                case 2:

                    Debug.Print(" Line Point");

                    break;

                case 3:

                    Debug.Print(" Three Points");

                    break;

                case 4:

                    Debug.Print(" Line Line");

                    break;

                case 5:

                    Debug.Print(" Distance");

                    break;

                case 6:

                    Debug.Print(" Parallel");

                    break;

                case 7:

                    Debug.Print(" Angle");

                    break;

                case 8:

                    Debug.Print(" Normal");

                    break;

                case 9:

                    Debug.Print(" On Surface");

                    break;

                case 10:

                    Debug.Print(" Standard");

                    break;

                case 11:

                    Debug.Print(" Constraint-based");

                    break;

            }

            Debug.Print("");

 

            planeType = swRefPlaneFeatureData.Type;

            Debug.Print("Type of reference plane using IRefPlaneFeatureData::Type: ");

            switch (planeType)

            {

                case 0:

                    Debug.Print(" Invalid");

                    break;

                case 1:

                    Debug.Print(" Undefined");

                    break;

                case 2:

                    Debug.Print(" Line Point");

                    break;

                case 3:

                    Debug.Print(" Three Points");

                    break;

                case 4:

                    Debug.Print(" Line Line");

                    break;

                case 5:

                    Debug.Print(" Distance");

                    break;

                case 6:

                    Debug.Print(" Parallel");

                    break;

                case 7:

                    Debug.Print(" Angle");

                    break;

                case 8:

                    Debug.Print(" Normal");

                    break;

                case 9:

                    Debug.Print(" On Surface");

                    break;

                case 10:

                    Debug.Print(" Standard");

                    break;

                case 11:

                    Debug.Print(" Constraint-based");

                    break;

            }

            Debug.Print("");

 

            swModel.ClearSelection2(true);

        }

 

        /// <summary> 

        /// The SldWorks swApp variable is pre-assigned for you. 

        /// </summary> 

        public SldWorks swApp;

 

    }

}
This example shows how to get rib feature data.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified model document exists.
// 2. Open an Immediate window.
//
// Postconditions:
// 1. Opens the part document.
// 2. Creates Shell1, Plane1, and Rib1.
// 3. Inspect the FeatureManager design tree, the graphics area, and the
//    Immediate window.
//
// NOTE: Because the model is used elsewhere, do not save changes.
//---------------------------------------------------------------------------
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 InsertRib_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 Part;
        RefPlane myRefPlane;
        SketchSegment skSegment;
        SelectionMgr swSelMgr;
        Feature swFeat;
        RibFeatureData2 swRibFeat;
        bool boolstatus;
        int longstatus;
        int longwarnings;
 
        public void Main()
        {
            Part = swApp.OpenDoc6("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\block20.sldprt", 1, 0, "", ref longstatus, ref longwarnings);
            swApp.ActivateDoc2("block20", false, ref longstatus);
            Part = (ModelDoc2)swApp.ActiveDoc;
 
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.00878816842651986, 0.0396239999998897, -0.0292468281514857, false, 1, null, 0);
            Part.InsertFeatureShell(0.00254, false);
 
            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.00264031138414111, 0.028407059059532, -0.0613970439424634, true, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.059937899786064, 0.0277866864457792, -0.00877977980189826, true, 1, null, 0);
 
            myRefPlane = (RefPlane)Part.FeatureManager.InsertRefPlane(128, 0, 128, 0, 0, 0);
            Part.ClearSelection2(true);
 
            boolstatus = Part.Extension.SelectByID2("Plane1", "PLANE", 0.00664896553058725, 0.109417877974863, 0.0524178648701081, false, 0, null, 0);
            Part.SketchManager.InsertSketch(true);
 
            skSegment = Part.SketchManager.CreateLine(-0.085797, 0.021082, 0.0, -0.03423, 0.035134, 0.0);
            skSegment = Part.SketchManager.CreateLine(-0.03423, 0.035134, 0.0, 0.007726, 0.025357, 0.0);
            skSegment = Part.SketchManager.CreateLine(0.007726, 0.025357, 0.0, 0.111514, 0.039624, 0.0);
            Part.ClearSelection2(true);
 
            Part.SketchManager.InsertSketch(true);
            Part.ClearSelection2(true);
            boolstatus = Part.Extension.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, false, 0, null, 0);
            Part.FeatureManager.InsertRib(true, false, 0.00254, 0, false, false, true, 0.0174532925199433, false, false);
 
            swSelMgr = (SelectionMgr)Part.SelectionManager;
            swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1);
            swRibFeat = (RibFeatureData2)swFeat.GetDefinition();
 
            Debug.Print("Rib feature type as defined in swRibType_e: " + swRibFeat.Type);
            Debug.Print("Thickness: " + swRibFeat.Thickness);
            Debug.Print("Extrusion direction as defined in swRibExtrusionDirection_e: " + swRibFeat.ExtrusionDirection);
            Debug.Print("Rib has a draft? " + swRibFeat.EnableDraft);
            if (swRibFeat.EnableDraft)
            {
                Debug.Print("    Draft angle: " + swRibFeat.DraftAngle);
                Debug.Print("    Draft outward? " + swRibFeat.DraftOutward);
            }
            Debug.Print("Add material to reverse side of the rib? " + swRibFeat.FlipSide);
            Debug.Print("Rib is extruded on two sides of the midplane? " + swRibFeat.IsTwoSided);
            if (!swRibFeat.IsTwoSided)
            {
                Debug.Print("Single-sided rib is extruded on the reverse side? " + swRibFeat.ReverseThicknessDir);
            }
 
        }
 
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
 
        public SldWorks swApp;
 
    }
}
This example shows how to create a surface knit feature.

//-----------------------------------------------------
// Preconditions:
// 1. Verify that the specified part template
//    exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens a new part document.
// 2. Creates two surfaces.
// 3. Creates a surface knit feature using the two
//    selected surfaces.
// 4. Examine the graphics area, FeatureManager design
//    tree, and Immediate window.
//--------------------------------------------------------
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace Macro2CSharp.csproj
{
    public partial class SolidWorksMacro
    {
        ModelDoc2 swModel;
        ModelDocExtension swModelDocExt;
        SketchManager swSketchManager;
        SketchSegment swSketchSegment;
        FeatureManager swFeatureManager;
        SelectionMgr swSelectionManager;
        Feature swFeature;
        SurfaceKnitFeatureData swSurfaceKnitFeature;
 
        bool boolstatus;
 
 
        public void Main()
        {
            //Open new part document and create two surfaces
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2016\\templates\\Part.prtdot", 0, 0, 0);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            swSketchManager = (SketchManager)swModel.SketchManager;
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
            swSelectionManager = (SelectionMgr)swModel.SelectionManager;
            boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.ClearSelection2(true);
            swSketchSegment = (SketchSegment)swSketchManager.CreateEllipse(-0.0415374666666667, 0, 0, 0.0534585333333333, 0, 0, -0.0415374666666667, 0.0208618666666667, 0);
            swModel.ClearSelection2(true);
            swSketchManager.InsertSketch(true);
            swModel.ClearSelection2(true);
            boolstatus = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 4, null, 0);
            swFeatureManager.FeatureExtruRefSurface2(true, false, false, 0, 0, 0.05, 0.01, false, false, false,
            false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, false, false, false, false);
            swSelectionManager.EnableContourSelection = false;
            boolstatus = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, true, 0, null, 0);
            swModel.ClearSelection2(true);
            boolstatus = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, true, 1, null, 0);
            boolstatus = swModel.InsertPlanarRefSurface();
            swModel.ClearSelection2(true);
 
            // Select both surfaces and create surface knit feature
            boolstatus = swModelDocExt.SelectByID2("Surface-Extrude1", "BODYFEATURE", 0, 0, 0, false, 1, null, 0);
            boolstatus = swModelDocExt.SelectByID2("Surface-Plane1", "SURFACEBODY", 0, 0, 0, true, 1, null, 0);
            swFeature = (Feature)swFeatureManager.InsertSewRefSurface(true, false, false, 0.0001, 0.0001);
 
            // Get some surface knit feature data
            swSurfaceKnitFeature = (SurfaceKnitFeatureData)swFeature.GetDefinition();
            Debug.Print("Knit-surface feature: ");
            Debug.Print("  Knit tolerance: " + swSurfaceKnitFeature.KnitTolerance * 1000 + " mm");
            Debug.Print("  Maximum value for gap range: " + swSurfaceKnitFeature.MaxValueForGapRange * 1000 + " mm");
            Debug.Print("  Minimum value for gap range: " + swSurfaceKnitFeature.MinValueForGapRange * 1000 + " mm");
            Debug.Print("  Use gap filters? " + swSurfaceKnitFeature.UseGapFilters);
            Debug.Print("  Use merge entities? " + swSurfaceKnitFeature.UseMergeEntities);
            Debug.Print("  Try to form solid? " + swSurfaceKnitFeature.UseTryToFormSolid);
 
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to insert a sheet metal base flange.

//---------------------------------------------------------------------------------
// Preconditions: Verify that the specified part template exists.
//
// Postconditions:
// 1. Creates two boss extrudes and converts them to sheet metal parts.
// 2. Inserts a sheet metal base flange that connects the two sheet metal parts.
// 3. Examine the graphics area and FeatureManager design tree.
//---------------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
 
namespace Macro1CSharp.csproj
{
    partial class SolidWorksMacro
    {
        ModelDoc2 Part;
        bool boolstatus;
        long longstatus;
        int status;
 
        public void Main()
        {
            longstatus = (long)swApp.ResetUntitledCount(0, 0, 0);
            Part = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2016\\templates\\Part.prtdot", 0, 0, 0);
            swApp.ActivateDoc2("Part1", false, ref status);
            Part = (ModelDoc2)swApp.ActiveDoc;
 
            Part.SketchManager.InsertSketch(true);
            boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", -0.07320616684915, 0.04378582530511, 0.008882453015985, false, 0, null, 0);
            Part.ClearSelection2(true);
            object vSkLines = null;
            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.09520523544121, 0.05740695090967, 0, -0.03844330645187, -0.0429584598942, 0);
            Part.ShowNamedView2("*Trimetric", 8);
            Part.ClearSelection2(true);
            object myFeature = null;
            myFeature = Part.FeatureManager.FeatureExtrusion2(true, false, true, 0, 0, 0.01, 0.01, false, false, false, false, 0.01745329251994, 0.01745329251994, false, false, false, false, true, true, true, 0, 0, false);
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.0785775433435, 0.01894373057962, 0, true, 0, null, 0);
            boolstatus = Part.FeatureManager.InsertConvertToSheetMetal(0.002, false, false, 0.004, 0.002, 0, 0.5);
            Part.ClearSelection2(true);
 
            boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            Part.SketchManager.InsertSketch(true);
            Part.ClearSelection2(true);
            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.02256810687936, 0.06039039042219, 0, 0.02390260459754, -0.04039198125838, 0);
            Part.ClearSelection2(true);
            myFeature = Part.FeatureManager.FeatureExtrusion2(true, false, true, 0, 0, 0.01, 0.01, false, false, false, false, 0.01745329251994, 0.01745329251994, false, false, false, false, true, true, true, 0, 0, false);
            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.0009118315510932, 0.02609254832731, 0, true, 0, null, 0);
            boolstatus = Part.FeatureManager.InsertConvertToSheetMetal(0.002, false, false, 0.004, 0.002, 0, 0.5);
            Part.ClearSelection2(true);
 
            Part.SketchManager.InsertSketch(true);
            boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            Part.ClearSelection2(true);
            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.05411927414525, 0.01318437124604, 0, -0.007403979976402, -0.001979918613586, 0);
            CustomBendAllowance customBendAllowanceData = null;
            customBendAllowanceData = null;
            myFeature = Part.FeatureManager.InsertSheetMetalBaseFlange2(0.002, false, 0.004, 0.02, 0.01, false, 0, 0, 1, customBendAllowanceData, false, 2, 0.0001, 0.0001, 0.5, true, false, true, true);
            Part.ClearSelection2(true); 
        }
 
        public SldWorks swApp; 
    } 
}
This example shows how to insert a sheet metal gusset feature and modify its data.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\api\SMGussetAPI.sldprt.
// 2. Open an Immediate window.
//
// Postconditions:
// 1. Inserts four sheet metal gussets.
// 2. Press F5 repeatedly and observe the gusset modifications.
// 3. Inspect the Immediate window for the flatten settings of all gussets.
// 4. Expand Flat-Pattern in the FeatureManager design tree, right-click 
//    Flat-Pattern(1), and click Unsuppress.
// 5. Observe the center marks and profiles of all the gussets in their
//    flattened states.
//
// NOTE: Because the model is used elsewhere, do not save changes.
// ---------------------------------------------------------------------------
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 InsertSMGusset_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 Part;
        Feature myFeature;
        Feature myFeature1;
        Feature myFeature2;
        Feature myFeature3;
        Feature swFeat;
        SMGussetFeatureData swFeatData;
 
        bool boolstatus;
 
        public void Main()
        {
            Part = (ModelDoc2)swApp.ActiveDoc;
 
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.0538403893476698, 0.0036701308754914, 0.05530817474488, false, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.0177780871801474, -0.0307393226379986, 0.0341128529187245, true, 0, null, 0);
 
            // Gusset #1 insertion parameters
            //1.  bOffset                    = True
            //2.  dOffset                    = 50 mm
            //3.  bFlipOffsetSide            = False
            //4.  profDimType                = 0 (indent depth dimensioning scheme)
            //5.  dIndentDepth               = 10 mm
            //6.  dLength                    = 0
            //7.  bUseAngle                  = False
            //8.  dHeight                    = 0
            //9   dAngle                     = 0
            //10. bFlipSides                 = False
            //11. dWidth                     = 10 mm
            //12. dThickness                 = 3 mm
            //13. bDraft                     = True
            //14. dDraftAngle                = 3 degrees
            //15. bInnerCornerFillet         = True
            //16. dInnerCornerFilletRadius   = 2 mm
            //17. bOuterCornerFillet         = True
            //18. dOuterCornerFilletRadius   = 1 mm
            //19. gussetType                 = 0 (rounded back)
            //20  bEdgeFillet                = False
            //21. dEdgeFilletRadius          = 0 mm
            //22. bOverrideDoc               = True
            //23. bShowProfile               = True
            //24. bShowCenter                = True
 
            myFeature = Part.FeatureManager.InsertSheetMetalGussetFeature3(true, 0.05, false, (int)swSheetMetalGussetProfileDimType_e.swSheetMetalGussetProfileDimType_IndentDepth, 0.01, 0, false, 0, 0, true,
            0.01, 0.003, true, 3 * 0.0175, true, 0.002, true, 0.001, (int)swSheetMetalRibGussetType_e.swSheetMetalRibGussetType_Rounded, false,
            0, true, true, true);
            Part.ClearSelection2(true);
 
            // Gusset #2 insertion parameters (same as for Gusset #1 with the following exceptions)
            //2.  dOffset                = 30 mm
            //19. gussetType             = 1 (flat back)
            //20  bEdgeFillet            = True
            //21. dEdgeFilletRadius      = 1 mm
 
            //Select faces
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.0538403893476698, 0.0036701308754914, 0.05530817474488, false, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.0177780871801474, -0.0307393226379986, 0.0341128529187245, true, 0, null, 0);
 
            myFeature1 = Part.FeatureManager.InsertSheetMetalGussetFeature3(true, 0.03, false, (int)swSheetMetalGussetProfileDimType_e.swSheetMetalGussetProfileDimType_IndentDepth, 0.01, 0, false, 0, 0, false,
            0.01, 0.003, true, 3 * 0.0175, true, 0.002, true, 0.001, (int)swSheetMetalRibGussetType_e.swSheetMetalRibGussetType_Flat, true,
            0.001, true, true, true);
            Part.ClearSelection2(true);
 
            // Gusset #3 insertion parameters (same as for Gusset #1 with the following exceptions)
            //2.  dOffset                = 30 mm
            //4.  profDimType            = 1 (length + height dimensioning scheme)
            //5.  dIndentDepth           = 0 mm
            //6.  dLength                = 25 mm
            //7.  bUseAngle              = False
            //8.  dHeight                = 15 mm
            //9   dAngle                 = 0
            //10. bFlipSides             = False
            //19. gussetType             = 1 (flat back)
            //20  bEdgeFillet            = True
            //21. dEdgeFilletRadius      = 1 mm
 
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.0538403893476698, 0.0036701308754914, 0.05530817474488, false, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.0177780871801474, -0.0307393226379986, 0.0341128529187245, true, 0, null, 0);
 
            myFeature2 = Part.FeatureManager.InsertSheetMetalGussetFeature3(true, 0.03, false, (int)swSheetMetalGussetProfileDimType_e.swSheetMetalGussetProfileDimType_ProfileDimensions, 0, 0.025, false, 0.015, 0, false,
            0.02, 0.003, true, 3 * 0.0175, true, 0.002, true, 0.001, (int)swSheetMetalRibGussetType_e.swSheetMetalRibGussetType_Flat, true,
            0.001, true, true, true);
            Part.ClearSelection2(true);
 
            // Gusset #4 insertion parameters (same as for Gusset #1 with the following exceptions)
            //2.  dOffset                = 30 mm
            //20  bEdgeFillet            = True
            //21. dEdgeFilletRadius      = 1 mm
 
            //Select orientation and position references
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.0538403893476129, -0.00224553153327633, 0.087801420904043, true, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.0235965800548001, -0.0307393226379986, 0.0897844682415894, true, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("Line1@Sketch6", "EXTSKETCHSEGMENT", -0.00609049483400968, -0.0895139047397037, 0, true, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("Point1@Sketch7", "EXTSKETCHPOINT", 0.0180407947995604, -0.0762728416981986, 0, true, 0, null, 0);
 
            myFeature3 = Part.FeatureManager.InsertSheetMetalGussetFeature3(true, 0.03, false, (int)swSheetMetalGussetProfileDimType_e.swSheetMetalGussetProfileDimType_IndentDepth, 0.01, 0, false, 0, 0, false,
            0.01, 0.003, true, 3 * 0.0175, true, 0.002, true, 0.001, (int)swSheetMetalRibGussetType_e.swSheetMetalRibGussetType_Rounded, true,
            0.001, true, true, true);
            Part.ClearSelection2(true);
 
            System.Diagnostics.Debugger.Break();
 
            //Five modifications to gusset feature data:
 
            //a. Modify type, draft, and outer corner fillet options for gusset #1
            boolstatus = Part.Extension.SelectByID2("Sheet Metal Gusset1", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swFeat = (Feature)((SelectionMgr)(Part.SelectionManager)).GetSelectedObject6(1, -1);
 
            swFeatData = (SMGussetFeatureData)swFeat.GetDefinition();
            swFeatData.AccessSelections(Part, null);
 
            swFeatData.GussetType = 1; //flat back
            swFeatData.DraftSideFaces = false;
            swFeatData.FilletOuterCorners = false; //no outer corner fillet
           
            Debug.Print("Sheet Metal Gusset1 Flatten Settings");
            Debug.Print("  Override document property settings? " + swFeatData.OverrideDocSettings);
            Debug.Print("  Show center marks? " + swFeatData.ShowCenter);
            Debug.Print("  Show profile? " + swFeatData.ShowProfile);
 
            swFeat.ModifyDefinition(swFeatData, Part, null);
            swFeatData.ReleaseSelectionAccess();
 
            System.Diagnostics.Debugger.Break();
 
            //b. Modify orientation reference of gusset #3
            boolstatus = Part.Extension.SelectByID2("Sheet Metal Gusset3", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swFeat = (Feature)((SelectionMgr)(Part.SelectionManager)).GetSelectedObject6(1, -1);
 
            swFeatData = (SMGussetFeatureData)swFeat.GetDefinition();
            swFeatData.AccessSelections(Part, null);
 
            boolstatus = Part.Extension.SelectByID2("Line1@Sketch6", "EXTSKETCHSEGMENT", -0.00609049483400968, -0.0895139047397037, 0, true, 0, null, 0);
 
            object refLine = null;
            refLine = ((SelectionMgr)(Part.SelectionManager)).GetSelectedObject6(1, -1);
            swFeatData.ReferenceLine = refLine;
 
            swFeat.ModifyDefinition(swFeatData, Part, null);
 
            System.Diagnostics.Debugger.Break();
 
            //c. Modify legs of gusset #2: select one bend face instead of two flat faces
            boolstatus = Part.Extension.SelectByID2("Sheet Metal Gusset2", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swFeat = (Feature)((SelectionMgr)(Part.SelectionManager)).GetSelectedObject6(1, -1);
 
            swFeatData = (SMGussetFeatureData)swFeat.GetDefinition();
            swFeatData.AccessSelections(Part, null);
 
            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.03831148650454, -0.0327672470662037, 0.147978181958194, false, 0, null, 0);
 
            object newBendFace = null;
            Face2[] bendfaces = new Face2[1];
            bendfaces[0] = (Face2)((SelectionMgr)(Part.SelectionManager)).GetSelectedObject6(1, -1);
 
            newBendFace = bendfaces;
            swFeatData.SupportingFaces = newBendFace;
            Debug.Print("Sheet Metal Gusset2 Flatten Settings");
            Debug.Print("  Override document property settings? " + swFeatData.OverrideDocSettings);
            Debug.Print("  Show center marks? " + swFeatData.ShowCenter);
            Debug.Print("  Show profile? " + swFeatData.ShowProfile);
 
            swFeat.ModifyDefinition(swFeatData, Part, null);
 
            System.Diagnostics.Debugger.Break();
 
            //d. Modify reference position of gusset #3 - 3 mm away from vertex of hexagonal cut
            boolstatus = Part.Extension.SelectByID2("Sheet Metal Gusset3", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swFeat = (Feature)((SelectionMgr)(Part.SelectionManager)).GetSelectedObject6(1, -1);
 
            swFeatData = (SMGussetFeatureData)swFeat.GetDefinition();
            swFeatData.AccessSelections(Part, null);
 
            boolstatus = Part.Extension.SelectByID2("", "VERTEX", -0.0538403893475499, -0.0100654290631334, 0.205954465964501, false, 0, null, 0);
 
            object refPoint = null;
            refPoint = ((SelectionMgr)(Part.SelectionManager)).GetSelectedObject6(1, -1);
            swFeatData.ReferencePoint = refPoint;
            Debug.Print("Sheet Metal Gusset3 Flatten Settings");
            Debug.Print("  Override document property settings? " + swFeatData.OverrideDocSettings);
            Debug.Print("  Show center marks? " + swFeatData.ShowCenter);
            Debug.Print("  Show profile? " + swFeatData.ShowProfile);
 
            swFeat.ModifyDefinition(swFeatData, Part, null);
 
            System.Diagnostics.Debugger.Break();
 
            //e. Modify type and inner corner fillet options for gusset #4
            boolstatus = Part.Extension.SelectByID2("Sheet Metal Gusset4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swFeat = (Feature)((SelectionMgr)(Part.SelectionManager)).GetSelectedObject6(1, -1);
 
            swFeatData = (SMGussetFeatureData)swFeat.GetDefinition();
            swFeatData.AccessSelections(Part, null);
 
            swFeatData.GussetType = 0; //rounded back
            swFeatData.FilletInnerCorners = false; //no inner corner fillet
            
            Debug.Print("Sheet Metal Gusset4 Flatten Settings");
            Debug.Print("  Override document property settings? " + swFeatData.OverrideDocSettings);
            Debug.Print("  Show center marks? " + swFeatData.ShowCenter);
            Debug.Print("  Show profile? " + swFeatData.ShowProfile);
 
            swFeat.ModifyDefinition(swFeatData, Part, null);
            swFeatData.ReleaseSelectionAccess();
 
 
        }
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
 
        public SldWorks swApp;
 
    }
}
This example shows how to insert a lofted bend feature in a sheet metal part and get the lofted bend feature data.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified part template exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens a new part.
// 2. Creates a sketch on Front Plane, a reference plane parallel to 
//    Front Plane, and a sketch on that reference plane.
// 3. Selects the sketches and inserts a lofted bend.
// 4. Inspect the Immediate window, FeatureManager design, and graphics area.
//---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
namespace Macro1CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 Part;
        Feature feat;
        RefPlane refPlane;
        SketchSegment skSegment;
        LoftedBendsFeatureData lbfd;
 
        bool boolstatus;
 
        public void Main()
        {
            // Open new part and create a sketch, a reference plane, and another sketch
            // on that reference plane
            Part = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2016\\templates\\Part.prtdot", 0, 0, 0);
            boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            Part.ClearSelection2(true);
            Part.SketchManager.InsertSketch(true);
            skSegment = (SketchSegment)Part.SketchManager.CreateLine(0.0, 0.0, 0.0, 0.024074, 0.024074, 0.0);
            skSegment = (SketchSegment)Part.SketchManager.CreateLine(0.024074, 0.024074, 0.0, 0.076952, 0.024074, 0.0);
            skSegment = (SketchSegment)Part.SketchManager.CreateLine(0.076952, 0.024074, 0.0, 0.101026, 0.0, 0.0);
            Part.ClearSelection2(true);
            Part.SketchManager.InsertSketch(true);
            boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
            refPlane = (RefPlane)Part.FeatureManager.InsertRefPlane(8, 0.05, 0, 0, 0, 0);
            Part.ClearSelection2(true);
            boolstatus = Part.Extension.SelectByID2("Plane1", "PLANE", 0, 0, 0, false, 0, null, 0);
            Part.SketchManager.InsertSketch(true);
            skSegment = (SketchSegment)Part.SketchManager.CreateLine(-0.031383, 0.0, 0.0, 0.047146, 0.060616, 0.0);
            skSegment = (SketchSegment)Part.SketchManager.CreateLine(0.047146, 0.060616, 0.0, 0.058036, 0.060616, 0.0);
            skSegment = (SketchSegment)Part.SketchManager.CreateLine(0.058036, 0.060616, 0.0, 0.129686, 0.002436, 0.0);
            Part.ClearSelection2(true);
            Part.SketchManager.InsertSketch(true);
 
            // Select the sketches for the lofted bend feature
            boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 1, null, 0);
            boolstatus = Part.Extension.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, true, 1, null, 0);
 
            // Insert a lofted bend feature with two bends
            feat = Part.FeatureManager.InsertSheetMetalLoftedBend2(0, 0.0007366, false, 0.0007366, true, (int)swLoftedBendFacetOptions_e.swBendsPerTransitionSegment, 0, 2, 0, 0);
 
            // Get lofted bend feature data
            lbfd = (LoftedBendsFeatureData)feat.GetDefinition();
            Debug.Print("Number of sketch profiles in this feature: " + lbfd.GetProfileCount());
            Debug.Print("Thickness: " + lbfd.Thickness);
            Debug.Print("Reverse thickness direction? " + lbfd.Direction);
            Debug.Print("Faceting option as defined in swLoftedBendFacetOptions_e: " + lbfd.FacetingOption);
            Debug.Print("Faceting option value: " + lbfd.FacetValue);
            Debug.Print("Formed? " + lbfd.FormedMethod);
            Debug.Print("Calculate facet transitions using vertexes? " + lbfd.ReferToEndPoint);
 
        }
 
        public SldWorks swApp;
 
    }
}
This example shows how to insert a structural weldment feature using a custom weldment profile configuration and structural member groups.

//---------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified library feature and part document template
//    exist.
// 2. Verify that a valid pathname exists in Parts in Tools > Options > 
//    System Options > Default Templates.
// 3. Create C:\Test\Pipes.
// 4. Open the Immediate window.
//
// Postconditions:
// 1. Opens the specified library feature, adds the nxn configuration, 
//    saves the library feature as nxn.sldlfp, and closes the new library 
//    feature, which is called a custom weldment profile when used to create
//    structural weldment features.
// 2. Creates a new part document that contains a sketch of two
//    rectangles.
// 3. Creates a weldment and two structural member features using the 
//    sketch and the nxn configuration of the custom weldment profile created in
//    step 1.
// 4. Rotates Pipes nxn(1).
// 5. Examine the FeatureManager design tree, graphics area, and
//    the Immediate window.
//---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            FeatureManager swFeatMgr = default(FeatureManager);
            SelectionMgr swSelMgr = default(SelectionMgr);
            SketchManager swSketchMgr = default(SketchManager);
            FeatureManager swFeatureMgr = default(FeatureManager);
            ConfigurationManager swConfigMgr = default(ConfigurationManager);
            Configuration swConfig = default(Configuration);
            Feature swFeature = default(Feature);
            StructuralMemberGroup swStructuralMemberGroup1 = default(StructuralMemberGroup);
            StructuralMemberGroup swStructuralMemberGroup2 = default(StructuralMemberGroup);
            Feature swWeldFeat = default(Feature);
            StructuralMemberFeatureData swStructuralMemberFeatData = default(StructuralMemberFeatureData);
            bool status = false;
            int errors = 0;
            int warnings = 0;
            string libFeature = null;
            string newLibFeature = null;
            string macroFolder = null;
            string template = null;
            object sketchLines = null;
            SketchSegment[] segs1 = new SketchSegment[2];
            object[] groupArray1 = new object[1];
            DispatchWrapper[] groups1 = new DispatchWrapper[1];
            SketchSegment[] segs2 = new SketchSegment[2];
            DispatchWrapper[] groups2 = new DispatchWrapper[1];
            object[] groupArray2 = new object[1];
            StructuralMemberGroup group = default(StructuralMemberGroup);
            object[] groups = new object[2];
            object[] segs = new object[2];
            string weldmentProfile = null;
            string weldmentConfigurationName = null;
 
            //Open existing library feature, add nxn configuration,
            //and save library feature as nxn.sldlfp
            libFeature = "C:\\Program Files\\SolidWorks Corp\\SOLIDWORKS\\lang\\english\\weldment profiles\\ansi inch\\pipe\\0.5 sch 40.sldlfp";
            swModel = (ModelDoc2)swApp.OpenDoc6(libFeature, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByID2("0.5 sch 40.SLDPRT", "COMPONENT", 0, 0, 0, false, 0, null, 0);
            swModel.ClearSelection2(true);
            swConfigMgr = (ConfigurationManager)swModel.ConfigurationManager;
            swConfig = (Configuration)swConfigMgr.AddConfiguration("nxn", "", "", (int)swConfigurationOptions2_e.swConfigOption_DontActivate, "", "");
            newLibFeature = "C:\\Test\\Pipes\\nxn.sldlfp";
            status = swModelDocExt.SaveAs(newLibFeature, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
            swModel = null;
            swApp.CloseDoc(newLibFeature);
 
            //Open new part document and
            //create weldment and structural members
            macroFolder = swApp.GetCurrentMacroPathFolder();
            swApp.SetCurrentWorkingDirectory(macroFolder);
            template = swApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            swModel = (ModelDoc2)swApp.NewDocument(template, 0, 0, 0);
            swFeatMgr = (FeatureManager)swModel.FeatureManager;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            swModel.ClearSelection2(true);
            swSketchMgr = (SketchManager)swModel.SketchManager;
            sketchLines = (object)swSketchMgr.CreateCornerRectangle(-0.1872393706766, 0.1133237194389, 0, -0.07003610048208, 0.009188409684237, 0);
            swModel.ClearSelection2(true);
            sketchLines = (object)swSketchMgr.CreateCornerRectangle(0.06513561531715, 0.03369083550887, 0, 0.1807053904567, -0.08106219210316, 0);
            swSketchMgr.InsertSketch(true);
            swModel.ViewZoomtofit2();
            swFeatureMgr = (FeatureManager)swModel.FeatureManager;
            swFeature = (Feature)swFeatureMgr.InsertWeldmentFeature();
            swStructuralMemberGroup1 = (StructuralMemberGroup)swFeatMgr.CreateStructuralMemberGroup();
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByID2("Line1@Sketch1", "EXTSKETCHSEGMENT", -0.1495427140733, 0.1133237194389, 0, false, 0, null, 0);
            status = swModelDocExt.SelectByID2("Line2@Sketch1", "EXTSKETCHSEGMENT", -0.1872393706766, 0.08238014634844, 0, true, 0, null, 0);
            segs1[0] = (SketchSegment)swSelMgr.GetSelectedObject6(1, 0);
            segs1[1] = (SketchSegment)swSelMgr.GetSelectedObject6(2, 0);
            swStructuralMemberGroup1.Segments = segs1;
            swStructuralMemberGroup1.Angle = 0.785714285714286; //radians
            swStructuralMemberGroup1.ApplyCornerTreatment = true;
            swStructuralMemberGroup1.CornerTreatmentType = (int)swSolidworksWeldmentEndCondOptions_e.swEndConditionMiter;
            swStructuralMemberGroup1.MirrorProfile = true;
            swStructuralMemberGroup1.MirrorProfileAxis = (int)swMirrorProfileOrAlignmentAxis_e.swMirrorProfileOrAlignmentAxis_Vertical;
 
            groupArray1[0] = (object)swStructuralMemberGroup1;
            groups1[0] = new DispatchWrapper(groupArray1[0]);
 
            weldmentProfile = "C:\\Test\\Pipes\\nxn.SLDLFP";
            weldmentConfigurationName = "nxn";
            swFeature = (Feature)swFeatureMgr.InsertStructuralWeldment5(weldmentProfile, (int)swConnectedSegmentsOption_e.swConnectedSegments_SimpleCut, false, (groups1), weldmentConfigurationName);
            swModel.ClearSelection2(true);
 
            swStructuralMemberGroup2 = (StructuralMemberGroup)swFeatMgr.CreateStructuralMemberGroup();
            status = swModelDocExt.SelectByID2("Line5@Sketch1", "EXTSKETCHSEGMENT", 0.1185825251083, 0.03369083550887, 0, false, 0, null, 0);
            status = swModelDocExt.SelectByID2("Line6@Sketch1", "EXTSKETCHSEGMENT", 0.06513561531715, -0.02774616865332, 0, true, 0, null, 0);
            segs2[0] = (SketchSegment)swSelMgr.GetSelectedObject6(1, 0);
            segs2[1] = (SketchSegment)swSelMgr.GetSelectedObject6(2, 0);
 
            swStructuralMemberGroup2.Segments = segs2;
            swStructuralMemberGroup2.AlignAxis = (int)swMirrorProfileOrAlignmentAxis_e.swMirrorProfileOrAlignmentAxis_Vertical;
 
            groupArray2[0] = (object)swStructuralMemberGroup2;
            groups2[0] = new DispatchWrapper(groupArray2[0]);
 
            swFeature = (Feature)swFeatureMgr.InsertStructuralWeldment5(weldmentProfile, (int)swConnectedSegmentsOption_e.swConnectedSegments_SimpleCut, false, (groups2), weldmentConfigurationName);
            swModel.ClearSelection2(true);
 
            //Get feature data for each structural member group
            status = swModelDocExt.SelectByID2("Pipes nxn(1)", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swWeldFeat = (Feature)swSelMgr.GetSelectedObject6(1, 0);
            swStructuralMemberFeatData = (StructuralMemberFeatureData)swWeldFeat.GetDefinition();
            swStructuralMemberFeatData.AccessSelections(swModel, null);
            Debug.Print("");
            Debug.Print("Groups count: " + swStructuralMemberFeatData.GetGroupsCount());
            Debug.Print("  Feature name: " + swWeldFeat.Name);
            Debug.Print("    Custom weldment profile configuration name: " + swStructuralMemberFeatData.ConfigurationName);
            Debug.Print("    Transfer material? " + swStructuralMemberFeatData.TransferMaterial);
            Debug.Print("    Library material profile: " + swStructuralMemberFeatData.LibraryProfileMaterial);
 
            groups = (object[])swStructuralMemberFeatData.Groups;
            long i = 0;
            long j = 0;
            Debug.Print("    Group:");
            for (i = 0; i < groups.Length; i++)
            {
                group = (StructuralMemberGroup)groups[i];
                Debug.Print("      Segment count: " + group.GetSegmentsCount());
                Debug.Print("      Rotational angle: " + group.Angle);
                Debug.Print("      Apply corner treatment: " + group.ApplyCornerTreatment);
                Debug.Print("      Corner treatment type: " + group.CornerTreatmentType);
                Debug.Print("      Mirror profile: " + group.MirrorProfile);
                Debug.Print("      Mirror profile axis: " + group.MirrorProfileAxis);
                Debug.Print("      Gap within: " + group.GapWithinGroup);
                segs = (object[])group.Segments;
                for (j = 0; j < segs.Length; j++)
                {
                    ((SketchSegment)segs[j]).Select(false);
                }
            }
            swStructuralMemberFeatData.ReleaseSelectionAccess();

            status = swModelDocExt.SelectByID2("Pipes nxn(2)", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swWeldFeat = (Feature)swSelMgr.GetSelectedObject6(1, 0);
            swStructuralMemberFeatData = (StructuralMemberFeatureData)swWeldFeat.GetDefinition();
            swStructuralMemberFeatData.AccessSelections(swModel, null);
            Debug.Print("");
            Debug.Print("Groups count: " + swStructuralMemberFeatData.GetGroupsCount());
            Debug.Print("  Feature name: " + swWeldFeat.Name);
            Debug.Print("    Custom weldment profile configuration name: " + swStructuralMemberFeatData.ConfigurationName);
            Debug.Print("    Transfer material? " + swStructuralMemberFeatData.TransferMaterial);
            Debug.Print("    Library material profile: " + swStructuralMemberFeatData.LibraryProfileMaterial);
 
            groups = (object[])swStructuralMemberFeatData.Groups;
            Debug.Print("    Group:");
            for (i = 0; i < groups.Length; i++)
            {
                group = (StructuralMemberGroup)groups[i];
                Debug.Print("      Segment count: " + group.GetSegmentsCount());
                Debug.Print("      Rotational angle: " + group.Angle);
                Debug.Print("      Apply corner treatment: " + group.ApplyCornerTreatment);
                Debug.Print("      Corner treatment type: " + group.CornerTreatmentType);
                Debug.Print("      Mirror profile: " + group.MirrorProfile);
                Debug.Print("      Mirror profile axis: " + group.MirrorProfileAxis);
                Debug.Print("      Gap within: " + group.GapWithinGroup);
                segs = (object[])group.Segments;
                for (j = 0; j < segs.Length; j++)
                {
                    ((SketchSegment)segs[j]).Select(false);
                }
            }
            swStructuralMemberFeatData.ReleaseSelectionAccess();
            swModel.ClearSelection2(true);
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to insert a weldment cut list into the FeatureManager design tree.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\assemblymates\bracket.sldprt.
// 2. Click Tools > Options > System Options > FeatureManager >
//    Solid Bodies > Show > OK.
// 3. Expand the Solid Bodies(1) folder in the FeatureManager design tree
//    and note its contents.
//
// Postconditions:
// 1. Inserts a cut-list-item folder feature containing the specified
//    weldment body.
// 2. Expand the Cut-List-Item1 folder in the Solid Bodies(1) folder
//    in the the FeatureManager design tree to verify step 1.
//
// NOTE: Because this part is used elsewhere,
// do not save changes.
//----------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

namespace InsertWeldmentCutList2_CSharp.csproj

{

    partial class SolidWorksMacro

    {

     

        ModelDoc2 Part;

        Body2[] obj = new Body2[1];

        Object[] v;

        long i;
 

        public void Main()

        {

            Part = (ModelDoc2)swApp.ActiveDoc;

            v = (object[])((PartDoc)Part).GetBodies2(0, true);

            for (i = 0; i <= v.GetUpperBound(0); i++)

            {

                obj[i] = (Body2)v[i];

            }

            Feature cutListFeature = default(Feature);

            cutListFeature = Part.FeatureManager.InsertWeldmentCutList2(obj);

        }

        public SldWorks swApp;

    }

}
This example shows how to create a wrap feature on multiple faces.

//---------------------------------------------------------------------------
// Preconditions: Verify that the part to open exists.
//
// Postconditions:
// 1. Opens the part.
// 2. Selects the plane on which to sketch a circle.
// 3. Sketches the circle.
// 4. Selects the sketch of the circle and the faces on which to
//    wrap it.
// 5. Creates the wrap feature.
// 6. Examine the FeatureManager design tree and part.
//
// NOTE: Because the part is used elsewhere, do not save changes.
//----------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            SketchManager swSketchManager = default(SketchManager);
            SketchSegment swSketchSegment = default(SketchSegment);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            FeatureManager swFeatureManager = default(FeatureManager);
            Feature swFeature = default(Feature);
            string fileName = null;
            bool status = false;
            int errors = 0;
            int warnings = 0;
 
            fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\molds\\telephone.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
 
            //Select the plane on which to sketch the circle for the wrap feature
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByID2("Plane8", "PLANE", 0, 0, 0, false, 0, null, 0);
 
            //Sketch the circle
            swSketchManager = (SketchManager)swModel.SketchManager;
            swSketchManager.InsertSketch(true);
            swModel.ClearSelection2(true);
            swSketchSegment = (SketchSegment)swSketchManager.CreateCircle(-0.035, 0.011624, 0.0, -0.031081, 0.018171, 0.0);
            swModel.ClearSelection2(true);
            swSketchManager.InsertSketch(true);
 
            //Select the sketch of the circle and the faces on which to wrap it
            //Because the type of wrap feature to create Scribe, no pull direction entity is selected
            status = swModelDocExt.SelectByID2("Sketch30", "SKETCH", 0, 0, 0, false, 4, null, 0);
            status = swModelDocExt.SelectByRay(-0.103709743982563, 0.00466186411857746, 0.0465727951450701, 1, 0, 0, 0.000421383417784414, 2, true, 1, 0);
            status = swModelDocExt.SelectByRay(-0.105251033879711, 0.0013155840361718, 0.0360382097004597, 1, 0, 0, 0.000421383417784414, 2, true, 1, 0);
            status = swModelDocExt.SelectByRay(-0.104507668954227, 0.00255494702965538, 0.0257514968545461, 1, 0, 0, 0.000421383417784414, 2, true, 1, 0);
            status = swModelDocExt.SelectByRay(-0.101403318635789, 0.0181709207475484, 0.0255036242558494, 1, 0, 0, 0.000421383417784414, 2, true, 1, 0);
            status = swModelDocExt.SelectByRay(-0.100395783628869, 0.0205257104351672, 0.0356664008024147, 1, 0, 0, 0.000421383417784414, 2, true, 1, 0);
            status = swModelDocExt.SelectByRay(-0.0997494761213602, 0.0190384748429869, 0.0484318396352955, 1, 0, 0, 0.000421383417784414, 2, true, 1, 0);
 
            //Create the wrap feature
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
            swFeature = (Feature)swFeatureManager.InsertWrapFeature2((int)swWrapSketchType_e.swWrapSketchType_Scribe, 0.00254, false, (int)swWrapMethods_e.swWrapMethods_SplineSurface, 5);
 
            swModel.ClearSelection2(true);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to create an intersect feature and get its data.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a part that contains the following intersecting features:
//    * Boss-Extrude1
//    * Boss-Extrude2
//    * Boss-Extrude3
//    * Boss-Extrude4
//    * Surface-Extrude1
// 2. Add reference, Microsoft.VisualBasic, to the project.
// 3. Open an Immediate window.
// 4. Multi-select Surface-Extrude1, Boss-Extrude3, and Boss-Extrude4 in the
//    FeatureManager design tree and press F5.
//
// Postconditions:
// 1. When the macro stops, inspect the blue intersect regions.
// 2. Press F5.
// 3. Inspect the Immediate window.
// 4. Right-click Intersect1 in the FeatureManager design tree and click
//    Roll Forward.
//
// NOTE: Because the model is used elsewhere, do not save changes.
// ---------------------------------------------------------------------------
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 ModifyIntersect_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        ModelDoc2 swModel;
        Feature swFeat;
        FeatureManager swFeatMgr;
        IntersectFeatureData featData;

        int intStatus;

        public void Main()
        {
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swFeatMgr = swModel.FeatureManager;

            object[] vResultingBodies = null;

            vResultingBodies = (object[])swFeatMgr.PreIntersect(false);
            //Do not cap planar surface openings of intersect feature
            swModel.ClearSelection2(true);

            int i = 0;
            Body2 swBody = default(Body2);

            Debug.Print("");
            //Color the intersect regions blue
            for (i = 0; i < vResultingBodies.Length; i++)
            {
                swBody = (Body2)vResultingBodies[i];
                Debug.Print("Intersect region " + i + 1 + " is a temporary body? " + swBody.IsTemporaryBody());
                intStatus = swBody.Display3(swModel, 16711680, (int)swTempBodySelectOptions_e.swTempBodySelectOptionNone);
                Debug.Print("Intersect region " + i + 1 + " is displayed (0 = yes)? " + intStatus);
            }

            System.Diagnostics.Debugger.Break();
            //Observe the intersect regions

            object intToExclude = null;
            bool[] boolArr = new bool[4];
            boolArr[0] = false;
            boolArr[1] = true;
            // Exclude region, vResultingBodies(2), from the intersect feature
            boolArr[2] = false;
            boolArr[3] = false;
            intToExclude = boolArr;
            swFeat = swFeatMgr.PostIntersect(intToExclude, true, false);

            Debug.Print("Feature name = " + swFeat.Name);
            featData = (IntersectFeatureData)swFeat.GetDefinition();

            Debug.Print("Merge touching regions into one body? " + featData.Merge);
            Debug.Print("Consume surfaces? " + featData.Consume);
            Debug.Print("Cap planar openings on surfaces? " + featData.CapPlanar);

            Debug.Print("Number of solids, surfaces, or planes used to create the intersect feature: " + featData.GetIntersectionsToolsCount());
            Debug.Print("Number of intersect regions: " + featData.GetIntersectionsCount());

        }

        public SldWorks swApp;

    }
}
This example shows how to create a Split feature.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a part document that contains a body that is bisected by the 
//    Top Plane.
// 2. Verify that c:\temp exists.
// 3. Open an Immediate window.
//
// Postconditions:
// 1. Creates Split1.
// 2. Saves a split body to c:\temp\Body1.sldprt.
// 3. Inspect the Immediate window, FeatureManager design tree, graphics area,
//    and c:\temp.
//---------------------------------------------------------------------------
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 CreateSplitBody2_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 swModel;
        SelectionMgr swSelMgr;
        ModelDocExtension swModelDocExt;
        Feature swFeat;
        FeatureManager swFeatMgr;
        SplitBodyFeatureData swSplitBodyFeat;
 
        bool boolstatus;
 
        public void Main()
        {
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModelDocExt = swModel.Extension;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            swFeatMgr = swModel.FeatureManager;
 
            //Select the cutting tool
            boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
 
            object vBodyNames = null;
            object[] bodiesToMark = new Body2[2];
            string[] bodyNames = new string[2];
            object[] bodyOrigins = new Vertex[2];
 
            //Get bodies that will result from the split operation
            object[] vResultingBodies = null;
            vResultingBodies = (object[])swFeatMgr.PreSplitBody2();
 
            swModel.ClearSelection2(true);
 
            //Set up the arrays for the post-split operation
 
            //If you do not want to assign body origin, set it to nothing so that the default origin is used
            bodyOrigins[0] = null;
            bodyOrigins[1] = null;
 
            bodiesToMark[0] = vResultingBodies[0];
            bodiesToMark[1] = vResultingBodies[1];
 
            //Save the first body to a separate part document
            //Substitute the name of the actual folder where to save the body
            bodyNames[0] = "c:\\temp\\Body1.sldprt";
            //Do not save the second body
            bodyNames[1] = "";
 
            DispatchWrapper[] preSplitBodies = null;
            preSplitBodies = (DispatchWrapper[])ObjectArrayToDispatchWrapperArray((bodiesToMark));
            vBodyNames = bodyNames;
            DispatchWrapper[] originsToUse = null;
            originsToUse = (DispatchWrapper[])ObjectArrayToDispatchWrapperArray((bodyOrigins));
 
            //Create the Split feature, consuming all split bodies
            swFeat = swFeatMgr.PostSplitBody2((preSplitBodies), true, (originsToUse), (vBodyNames), "");
 
            if (((swFeat != null)))
            {
                Debug.Print("Split feature: " + swFeat.Name);
                swSplitBodyFeat = (SplitBodyFeatureData)swFeat.GetDefinition();
                Debug.Print("Bodies consumed? " + swSplitBodyFeat.Consume);
                Debug.Print(" ");
            }
        }
 
        public DispatchWrapper[] ObjectArrayToDispatchWrapperArray(object[] Objects)
        {
            int ArraySize = 0;
            ArraySize = Objects.GetUpperBound(0);
            DispatchWrapper[] d = new DispatchWrapper[ArraySize + 1];
            int ArrayIndex = 0;
            for (ArrayIndex = 0; ArrayIndex <= ArraySize; ArrayIndex++)
            {
                d[ArrayIndex] = new DispatchWrapper(Objects[ArrayIndex]);
            }
            return d;
        }
 
 
        public SldWorks swApp;
    }
}
This example shows how to create a trimmed surface feature.

// ---------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified document template exists.
// 2. Open an Immediate window.
//
// Postconditions:
// 1. Creates a new model document with two intersecting surface extrude
//    features.
// 2. Selects Surface-Extrude2 as the trim tool and sets the trimming options.
// 3. Trims Surface-Extrude1.
// 4. Creates Surface-Trim1 in the FeatureManager design tree.
// 5. Inspect the Immediate window.
// ---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace CrateSurfTrimFeatData_CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            SketchManager swSketchMgr = default(SketchManager);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SketchSegment swSketchSegment = default(SketchSegment);
            FeatureManager swFeatureMgr = default(FeatureManager);
            SelectionMgr swSelMgr = default(SelectionMgr);
            Feature swFeat = default(Feature);
            SurfaceTrimFeatureData surfTrimFeatData = default(SurfaceTrimFeatureData);
            bool status = false;
 
            // Create new model document
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2015\\templates\\Part.prtdot", 0, 0, 0);
            swSketchMgr = (SketchManager)swModel.SketchManager;
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            swFeatureMgr = (FeatureManager)swModel.FeatureManager;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
 
            // Create two intersecting surfaces
            status = swModelDocExt.SelectByID2("Right Plane", "Plane", 0, 0, 0, false, 0, null, 0);
            swSketchMgr.InsertSketch(true);
            swSketchSegment = (SketchSegment)swSketchMgr.CreateLine(-0.068922, 0.023964, 0.0, 0.042733, 0.005543, 0.0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Line1", "SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);
            swFeatureMgr.FeatureExtruRefSurface2(true, false, false, 0, 0, 0.06604, 0.00254, false, false, false,
            false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, false, false, false,
            false);
            swSelMgr.EnableContourSelection = false;
 
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            swSketchMgr.InsertSketch(true);
            swSketchSegment = (SketchSegment)swSketchMgr.CreateLine(-0.041529, 0.023059, 0.0, -0.052625, -0.081662, 0.0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Line1", "SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);
            swFeatureMgr.FeatureExtruRefSurface2(false, false, false, 0, 0, 0.0889, 0.06604, false, false, false,
            false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, false, false, false,
            false);
            swSelMgr.EnableContourSelection = false;
 
            // Set the trimming options
            status = swFeatureMgr.PreTrimSurface(false, true, false, false);
 
            // Trim the surface
            status = swModelDocExt.SelectByID2("", "SURFACEBODY", 0.0289416986472588, 0.00781827749557351, 0.0290635845400971, true, 0, null, 0);
            swFeat = (Feature)swFeatureMgr.PostTrimSurface(true);
 
            swModel.ClearSelection2(true);
 
            surfTrimFeatData = (SurfaceTrimFeatureData)swFeat.GetDefinition();
 
            surfTrimFeatData.AccessSelections(swModel, null);
 
            Debug.Print(swFeat.Name);
            Debug.Print("  Number of pieces to keep: " + surfTrimFeatData.GetPiecesToKeepCount());
            Debug.Print("  Surface trim feature type as defined in swSurfaceTrimType_e: " + surfTrimFeatData.GetType());
            Debug.Print("");
 
            object[] varTrimTools = null;
            int i = 0;
 
            varTrimTools = (object[])surfTrimFeatData.TrimTools;
            Debug.Print("Trim tools:");
            for (i = 0; i <= surfTrimFeatData.GetTrimToolsCount() - 1; i++)
            {
                Debug.Print("  " + ((Feature)varTrimTools[i]).Name);
            }
 
            surfTrimFeatData.ReleaseSelectionAccess();
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to create an intersect feature that includes only the internal (hollow) regions between the intersecting regions.

//----------------------------------------------------
// Preconditions: Verify that the specified part exists.
//
// Postconditions:
// 1. Opens the specified part.
// 2. Selects Shell1 and Plane6.
// 3. Creates Intersect1 feature.
// 4. Examine the FeatureManager design tree.
//
// NOTE: Because the part is used elsewhere, do not save
// changes.
//----------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            FeatureManager swFeatureMgr = default(FeatureManager);
            Feature swFeature = default(Feature);
            object[] bodyArray = null;
            bool[] bodyExcludeArray = null;
            object excludeArray = null;
            bool status = false;
            int errors = 0;
            int warnings = 0;
            string fileName = null;
            int nbrBodies = 0;
            int i = 0;
 
            fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2017\\whatsnew\\parts\\pot.SLDPRT";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            swFeatureMgr = (FeatureManager)swModel.FeatureManager;
 
            //Select features for intersect feature
            status = swModelDocExt.SelectByID2("Shell1", "SOLIDBODY", 0, 0, 0, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("Plane6", "PLANE", 0, 0, 0, true, 0, null, 0);
 
            // Create intersect feature
            // * Do not cap planar surface openings of intersect feature
            // * Create internal regions
            bodyArray = (object[])swFeatureMgr.PreIntersect2(false, 1);
            swModel.ClearSelection2(true);
 
            nbrBodies = bodyArray.GetUpperBound(0);
            bodyExcludeArray = new bool[nbrBodies + 1];
            for (i = 0; i <= nbrBodies; i++)
            {
                bodyExcludeArray[i] = false;
            }
            excludeArray = bodyExcludeArray;
            swFeature = swFeatureMgr.PostIntersect(excludeArray, true, false);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to insert and modify a boundary feature.

//-------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified part document template exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens a new part.
// 2. Creates two boss-extrude features.
// 3. Selects a face on each boss-extrude feature.
// 4. Creates a boundary feature using the the selected faces.
// 5. Gets and sets some boundary feature data.
// 6. Examine the Immediate window, FeatureManager design tree,
//    and the graphics area.
//-------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SelectionMgr swSelectionMgr = default(SelectionMgr);
            FeatureManager swFeatureMgr = default(FeatureManager);
            Feature swFeature = default(Feature);
            SketchManager swSketchMgr = default(SketchManager);
            BoundaryBossFeatureData swBoundaryBossFeatureData = default(BoundaryBossFeatureData);
            bool status = false;
            object[] sketchLines = null;
            int nbrCurves = 0;
            object directionVectorEntity = null;
            int directionVectorEntityType = 0;
            int tangencyType = 0;
            object[] d1Curves = null;
            int curveType = 0;
            int i = 0;
 
            //Open new part document
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2016\\templates\\Part.prtdot", 0, 0, 0);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            //Create two boss-extrude features
            //and boundary feature
            status = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstToRectEntity, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, false);
            status = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, true);
            swSketchMgr = (SketchManager)swModel.SketchManager;
            sketchLines = (object[])swSketchMgr.CreateCornerRectangle(-0.107624731933299, 0.0371047716348016, 0, -0.083196263303762, -0.00987284730888405, 0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Line2", "SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);
            status = swModelDocExt.SelectByID2("Line1", "SKETCHSEGMENT", 0, 0, 0, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("Line4", "SKETCHSEGMENT", 0, 0, 0, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("Line3", "SKETCHSEGMENT", 0, 0, 0, true, 0, null, 0);
            swFeatureMgr = (FeatureManager)swModel.FeatureManager;
            swFeature = (Feature)swFeatureMgr.FeatureExtrusion3(true, false, false, 0, 0, 0.0508, 0.00254, false, false, false,
            false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, true, true, true,
            0, 0, false);
            status = swModelDocExt.SelectByID2("Right Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstToRectEntity, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, false);
            status = swModelDocExt.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, true);
            sketchLines = (object[])swSketchMgr.CreateCornerRectangle(-0.0391822613366912, 0.0227443468893966, 0, 0.0479123594660678, -0.0893283426445919, 0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Line2", "SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);
            status = swModelDocExt.SelectByID2("Line1", "SKETCHSEGMENT", 0, 0, 0, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("Line4", "SKETCHSEGMENT", 0, 0, 0, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("Line3", "SKETCHSEGMENT", 0, 0, 0, true, 0, null, 0);
            swFeature = (Feature)swFeatureMgr.FeatureExtrusion3(true, false, false, 0, 0, 0.0508, 0.0508, false, false, false,
            false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, true, true, true,
            0, 0, false);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("", "FACE", -0.0831962633037051, -0.000743092842242277, 0.0342529447572133, false, 8193, null, 0);
            status = swModelDocExt.SelectByID2("", "FACE", -0.0391822613366344, -0.00670639010576224, 0.0375699693011029, true, 16385, null, 0);
            swFeatureMgr.SetNetBlendCurveData(0, 0, 0, 0, 1, true);
            swFeatureMgr.SetNetBlendCurveData(0, 1, 0, 0.26179938779915, 1, true);
            swFeatureMgr.SetNetBlendDirectionData(0, 32, 0, false, false);
            swFeatureMgr.SetNetBlendDirectionData(1, 32, 0, false, false);
            swFeatureMgr.InsertNetBlend(1, 2, 0, false, 0.0001, true, true, true, true, false,
            -1, -1, false, -1, false, false, -1, false, -1, true);
 
            //Get boundary feature
            //Get and set some of its data
            status = swModelDocExt.SelectByID2("Boundary1", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swSelectionMgr = (SelectionMgr)swModel.SelectionManager;
            swFeature = (Feature)swSelectionMgr.GetSelectedObject6(1, -1);
            swBoundaryBossFeatureData = (BoundaryBossFeatureData)swFeature.GetDefinition();
            Debug.Print("Name of feature: " + swFeature.Name);
            swModel.ClearSelection2(true);
            status = swBoundaryBossFeatureData.AccessSelections(swModel, null);
            //Get number of curves
            nbrCurves = swBoundaryBossFeatureData.GetCurvesCount((int)swBoundaryBossDirection_e.swBoundaryBossDirection_First);
            Debug.Print("  Number of curves in Direction 1: " + nbrCurves);
            if (nbrCurves >= 0)
            {
                //Get tangency type
                tangencyType = swBoundaryBossFeatureData.GetGuideTangencyType((int)swBoundaryBossDirection_e.swBoundaryBossDirection_First, 0);
                if (tangencyType == (int)swBoundaryBossTangencyType_e.swBoundaryBossTangency_DirectionVector)
                {
                    directionVectorEntity = swBoundaryBossFeatureData.GetDirectionVector((int)swBoundaryBossDirection_e.swBoundaryBossDirection_First, 0);
                    status = swSelectionMgr.AddSelectionListObject(directionVectorEntity, null);
                    directionVectorEntityType = swSelectionMgr.GetSelectedObjectType3(1, -1);
                    Debug.Print("  Type of entity selected for Direction Vector for curve 1 in Direction 1: " + directionVectorEntityType);
                }
                else
                {
                    Debug.Print("  Tangency type for curve 1 in Direction 1: " + tangencyType);
                    Debug.Print("    NOTE: Tried to get entity for Direction Vector. Failed because");
                    Debug.Print("    tangency type must be 2 (swBoundaryBossTangencyType_e.swBoundaryBossTangency_DirectionVector),");
                    Debug.Print("    so type of entity used for Direction Vector is not available.");
                }
            }
             //Get and set draft angle
            Debug.Print("  Original draft angle for curve 1 in Direction 1: " + swBoundaryBossFeatureData.GetDraftAngle((int)swBoundaryBossDirection_e.swBoundaryBossDirection_First, 0));
            swBoundaryBossFeatureData.SetDraftAngle((int)swBoundaryBossDirection_e.swBoundaryBossDirection_First, 0, 0.015);
            Debug.Print("  Modified draft angle for curve 1 in Direction 1: " + swBoundaryBossFeatureData.GetDraftAngle((int)swBoundaryBossDirection_e.swBoundaryBossDirection_First, 0));
            //Flip draft angle
            swBoundaryBossFeatureData.SetDraftAngleReverseDirection((int)swBoundaryBossDirection_e.swBoundaryBossDirection_First, 0, true);
            Debug.Print("  Draft angle flipped for curve 1 in Direction 1: " + swBoundaryBossFeatureData.GetDraftAngleReverseDirection((int)swBoundaryBossDirection_e.swBoundaryBossDirection_First, 0));
            //Get curves
            swModel.ClearSelection2(true);
            d1Curves = (object[])swBoundaryBossFeatureData.D1Curves;
            for (i = 0; i < nbrCurves; i++)
            {
                status = swSelectionMgr.AddSelectionListObject(d1Curves[i], null);
                curveType = swSelectionMgr.GetSelectedObjectType3(i + 1, -1);
                Debug.Print("  Curve " + (i + 1) + " type: " + curveType);
            }
            Debug.Print("  Is thin feature? " + swBoundaryBossFeatureData.IsThinFeature());
            status = swFeature.ModifyDefinition(swBoundaryBossFeatureData, swModel, null);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to insert sketch text and a hole at the selected point on a face.

//----------------------------------------------------------------------------
// Preconditions: Open a model document and select a face.
//
// Postconditions: 
// 1. Creates a hole and inserts the specified text on the
//    face at its point of selection.
// 2. Examine the graphics area and FeatureManager design tree.
//----------------------------------------------------------------------------
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 InsertSketchText_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 swModel;
        SelectionMgr swSelMgr;
        MathPoint swMathPt;
        Face2 selFace;
        Entity selEnt;
        double[] selPt;
        object NewPt;
        MathUtility swMathUtil;
        MathTransform swMathTrans;
        SelectData selData;
        SketchManager swSketchMgr;
        SketchText skText;
        double[] ptArr = new double[3];
        object @params;
        Feature holeFeat;
        FeatureManager swFeatMgr;
 
        bool boolstatus;
 
        public object TransformPoint(Sketch Sketch1, double X, double Y, double Z)
        {
 
            ptArr[0] = X;
            ptArr[1] = Y;
            ptArr[2] = Z;
 
            swMathUtil = (MathUtility)swApp.GetMathUtility();
            swMathPt = (MathPoint)swMathUtil.CreatePoint((ptArr));
 
            @params = swMathPt.ArrayData;
 
            swMathTrans = Sketch1.ModelToSketchTransform;
            swMathPt = (MathPoint)swMathPt.MultiplyTransform(swMathTrans);
 
            NewPt = swMathPt.ArrayData;
 
            return NewPt;
 
        }
 
        public void Main()
        {
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            selFace = (Face2)swSelMgr.GetSelectedObject6(1, -1);
            selEnt = (Entity)selFace;
 
            selPt = (double[])swSelMgr.GetSelectionPoint2(1, -1);
 
            selData = swSelMgr.CreateSelectData();
 
            selData.X = selPt[0];
            selData.Y = selPt[1];
            selData.Z = selPt[2];
 
            swSketchMgr = swModel.SketchManager;
 
            swSketchMgr.InsertSketch(true);
 
            selPt = (double[])TransformPoint(swModel.IGetActiveSketch2(), selPt[0], selPt[1], selPt[2]);
 
            skText = (SketchText)swModel.InsertSketchText(selPt[0], selPt[1], selPt[2], "Hole", 0, 0, 0, 100, 100);
 
            @params = skText.GetCoordinates();
 
            swSketchMgr.InsertSketch(true);
 
            boolstatus = selEnt.Select4(false, selData);
 
            swFeatMgr = swModel.FeatureManager;
            holeFeat = swFeatMgr.SimpleHole2(0.001, true, false, false, 0, 0, 0.001, 0.001, false, false,
            false, false, 0, 0, false, false, false, false, true, true,
            false, false, false);
 
        }
 
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
 
        public SldWorks swApp;
 
    }
 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值