Hide Table of Contents

Get and Add Sketch Points in Hole Wizard Feature Example (C#)

This example shows how to get and add the sketch points in a Hole Wizard feature.

//------------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified part document template exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Creates a new part document.
// 2. Creates Boss-Extrude1 and #0-80 Tapped Hole1 features.
// 3. Selects #8-80 Tapped Hole1; i.e., the Hole Wizard feature.
// 4. Gets the number of sketch points in the Hole Wizard feature.
// 5. Adds two sketch points to the Hole Wizard feature; thus, adds two more
//    holes to the Hole Wizard feature.
// 6. Examine the Immediate window and 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);
            SketchManager swSketchMgr = default(SketchManager);
            FeatureManager swFeatureMgr = default(FeatureManager);
            Feature swFeature = default(Feature);
            SelectionMgr swSelectionMgr = default(SelectionMgr);
            WizardHoleFeatureData2 swWizardHoleFeatureData = default(WizardHoleFeatureData2);
            SketchPoint swSketchPoint = default(SketchPoint);
            object sketchLines = null;
            bool status = false;
            int count = 0;
            object[] points = null;
 
            //Create part with Hole Wizard feature
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SolidWorks 2015\\templates\\Part.prtdot", 0, 0, 0);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            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, 0, 0, 0.0968848174375125, -0.0708129015764598, 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.FeatureExtrusion2(truefalsefalse, 0, 0, 0.0254, 0.00254, falsefalsefalse,
            false, 0.0174532925199433, 0.0174532925199433, falsefalsefalsefalsetruetruetrue,
            0, 0, false);
            swSelectionMgr = (SelectionMgr)swModel.SelectionManager;
            swSelectionMgr.EnableContourSelection = false;
            status = swModelDocExt.SelectByID2("""FACE", 0.0471052662929878, -0.0336338467782298, 0.0253999999998769, false, 0, null, 0);
            swFeature = (Feature)swFeatureMgr.HoleWizard5(4, 0, 27, "#0-80", 1, 0.00119126, 0.0254, 0.020066, 0, 0,
            0, 0, 0, 0, 1, 0, 0, -1, -1, -1,
            "2B"falsetruetruetruetruefalse);
            swModel.ViewZoomtofit2();
            status = swModelDocExt.SelectByID2("#0-80 Tapped Hole1""BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swFeature = (Feature)swSelectionMgr.GetSelectedObject6(1, -1);
            swModel.ClearSelection2(true);
            swWizardHoleFeatureData = (WizardHoleFeatureData2)swFeature.GetDefinition();
            count = swWizardHoleFeatureData.GetSketchPointCount();
            Debug.Print(" Number of sketch points in original Hole Wizard Feature = " + count);
            points = (object[])swWizardHoleFeatureData.GetSketchPoints();
            foreach (object point in points)
            {
                swSketchPoint = (SketchPoint)point;
                swSketchPoint.Select4(falsenull);
            }
            status = swFeature.ModifyDefinition(swWizardHoleFeatureData, swModel, null);
            swModel.ClearSelection2(true);
 
            //Select sketch point of Hole Wizard feature
            //and add two sketch points to Hole Wizard feature
            status = swModelDocExt.SelectByID2("Sketch3""SKETCH", 0, 0, 0, false, 0, null, 0);
            swSketchMgr.AddToDB = true;
            swModel.EditSketch();
            swSketchPoint = swSketchMgr.CreatePoint(0.01, -0.04, 0);
            swSketchPoint = swSketchMgr.CreatePoint(0.01, -0.02, 0);
            swSketchMgr.InsertSketch(true);
            swSketchMgr.AddToDB = false;
            swModel.ForceRebuild3(true);
 
            //Get number of sketch points in modified Hole Wizard feature
            status = swModelDocExt.SelectByID2("#0-80 Tapped Hole1""BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swFeature = (Feature)swSelectionMgr.GetSelectedObject6(1, -1);
            swModel.ClearSelection2(true);
            swWizardHoleFeatureData = (WizardHoleFeatureData2)swFeature.GetDefinition();
            count = swWizardHoleFeatureData.GetSketchPointCount();
            Debug.Print(" Number of sketch points in modified Hole Wizard Feature = " + count);
            points = (object[])swWizardHoleFeatureData.GetSketchPoints();
            foreach (object point in points)
            {
                swSketchPoint = (SketchPoint)point;
                swSketchPoint.Select4(falsenull);
            }
            status = swFeature.ModifyDefinition(swWizardHoleFeatureData, swModel, null);
            swModel.ClearSelection2(true);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}


Provide feedback on this topic

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

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get and Add Sketch Points in Hole Wizard Feature Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

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

 Never show this message again
x

Web Help Content Version: API Help (English only) 2017 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.