Hide Table of Contents

Insert Extruded Reference Surface Example (C#)

This example shows how to insert an extruded surface into a model.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified part template exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Creates Surface-Extrude1 in the FeatureManager design tree.
// 2. Expand the Surface Bodies folder to verify that it contains:
//    * Surface-Extrude[1]
//    * Surface-Extrude[2]
//    * Surface-Extrude[3]
// 3. Inspect the Immediate window.
//---------------------------------------------------------------------------
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 InsertExtrudedSurface_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 Part;
        SelectionMgr selMgr;
        Feature surfExtrudeFeat;
        SurfExtrudeFeatureData surfExtrude;
        bool boolstatus;
        int longstatus;
 
        public void Main()
        {
            Part = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2016\\templates\\Part.prtdot", 0, 0, 0);
            swApp.ActivateDoc2("Part1"falseref longstatus);
            Part = (ModelDoc2)swApp.ActiveDoc;
            ModelView myModelView = default(ModelView);
            myModelView = (ModelView)Part.ActiveView;
            myModelView.FrameState = (int)swWindowState_e.swWindowMaximized;
            Part.SketchManager.InsertSketch(true);
            boolstatus = Part.Extension.SelectByID2("Front Plane""PLANE", -0.03891024234798, 0.02968528649877, 0.0003646590412283, false, 0, null, 0);
            Part.ClearSelection2(true);
            object vSkLines = null;
            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.05517876768764, 0.008130204900836, 0, -0.02399076855985, -0.0155939995639, 0);
            Part.ClearSelection2(true);
            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.003731897331531, 0.008130204900836, 0, 0.0285223581767, -0.02998846069981, 0);
            Part.ClearSelection2(true);
            SketchSegment skSegment = default(SketchSegment);
            skSegment = Part.SketchManager.CreateCircle(0.053579, 0.013995, 0.0, 0.06819, 0.018462, 0.0);
            Part.ClearSelection2(true);
            Part.SketchManager.InsertSketch(true);
            Part.ShowNamedView2("*Trimetric", 8);
            Part.ClearSelection2(true);
            boolstatus = Part.Extension.SelectByID2("Sketch1""SKETCH", 0, 0, 0, false, 0, null, 0);
 
            FeatureManager myFeatMr = default(FeatureManager);
            myFeatMr = Part.FeatureManager;
 
            // Create a blind surface extrude of 10 mm 
            // in two directions from the selected sketch 
            // in a direction normal to the selected sketch plane

            myFeatMr.FeatureExtruRefSurface2(falsefalsefalse, 0, 0, 0.01, 0.01, falsefalsefalse,
            false, 0.01745329251994, 0.01745329251994, falsefalsefalsefalsefalsefalsefalse,
            false);
 
            Part.ClearSelection2(true);
            selMgr = (SelectionMgr)Part.SelectionManager;
 
            // Get Surface-Extrude1 data
            boolstatus = Part.Extension.SelectByID2("Surface-Extrude1""BODYFEATURE", 0, 0, 0, false, 0, null, 0);
 
            surfExtrudeFeat = (Feature)selMgr.GetSelectedObject6(1, -1);
            surfExtrude = (SurfExtrudeFeatureData)surfExtrudeFeat.GetDefinition();
 
            surfExtrude.AccessSelections(Part, null);
 
            Debug.Print(surfExtrudeFeat.Name);
            Debug.Print("  Depth:");
            Debug.Print("    Forward direction: " + surfExtrude.GetDepth(true));
            Debug.Print("    Reverse direction: " + surfExtrude.GetDepth(false));
            Debug.Print("  End condition as defined in swSurfaceExtendEndCond_e:");
            Debug.Print("    Forward direction: " + surfExtrude.GetEndCondition(true));
            Debug.Print("    Reverse direction: " + surfExtrude.GetEndCondition(false));
            Debug.Print("  Reverse offset enabled:");
            Debug.Print("    Forward direction? " + surfExtrude.GetReverseOffset(true));
            Debug.Print("    Reverse direction? " + surfExtrude.GetReverseOffset(false));
            Debug.Print("  Translate surface setting enabled:");
            Debug.Print("    Forward direction? " + surfExtrude.GetTranslateSurface(true));
            Debug.Print("    Reverse direction? " + surfExtrude.GetTranslateSurface(false));
            Debug.Print("  Surface extruded in both directions? " + surfExtrude.BothDirections);
            Debug.Print("  Extrusion reversed? " + surfExtrude.ReverseDirection);
 
            surfExtrude.ReleaseSelectionAccess();
 
        }
 
 
        public SldWorks swApp;
 
    }



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Insert Extruded Reference Surface Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2016 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.