Hide Table of Contents

Create and Edit Circular Sketch Pattern Example (C#)

This example shows how to create and edit a circular sketch pattern.

// -----------------------------------------------------------------------------

// Preconditions:

//       (1) SolidWorks is running.

//       (2) The part template exists in the specified folder.

//

// Postconditions:

//         (1) A sketch is created.

//         (2) A circular sketch pattern is created in the open sketch.

//         (3) Sketch is closed.

//         (4) Circular sketch pattern is opened for editing.

//         (5) Circular sketch pattern is edited -- an instance of

//             the circular sketch pattern is deleted.

// -----------------------------------------------------------------------------

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

namespace CreateEditCircularPattern_CSharp.csproj

{

    partial class SolidWorksMacro

    {

        public void Main()

        {

            ModelDoc2 swModel = default(ModelDoc2);

            ModelDocExtension swModelDocExt = default(ModelDocExtension);

            SketchManager swSketchMgr = default(SketchManager);

            SketchSegment swSketchSegment = default(SketchSegment);

            object vSkLines = null;

            bool boolstatus = false;

            int longstatus = 0;

            // Reset the counts for untitled documents for this macro

            swApp.ResetUntitledCount(0, 0, 0);

            // Create a part document

            swModel = (ModelDoc2)swApp.NewDocument("C:\\Documents and Settings\\All Users\\Application Data\\SolidWorks\\SolidWorks 2010\\templates\\Part.prtdot", 0, 0, 0);

            swApp.ActivateDoc2("Part1", false, ref longstatus);

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swSketchMgr = swModel.SketchManager;

            swModelDocExt = swModel.Extension;

            // Sketch a circle

            swSketchSegment = swSketchMgr.CreateCircle(0.0, 0.0, 0.0, 0.045549, 0.013926, 0.0);

            // Clear any selections and change

            // the view orientation to Front

            swModel.ClearSelection2(true);

            swModel.ShowNamedView2("*Front", 1);

            // Create a rectangle

            vSkLines = swSketchMgr.CreateCornerRectangle(-0.005867589431389, 0.03694408160504, 0, 0.004563680668858, 0.02673012963188, 0);

            // Create a circular sketch pattern

            // using the rectangle

            boolstatus = swSketchMgr.CreateCircularSketchStepAndRepeat(0.03184378021964, 4.732863934409, 4, 1.570796326795, true, "", true, true, true);

            swModel.ClearSelection2(true);

            // Close the sketch and rebuild

            swSketchMgr.InsertSketch(true);

            // Select an entity in the circular sketch pattern

            // and open the circular sketch pattern to edit it

            boolstatus = swModelDocExt.SelectByID2("Line1@Sketch1", "EXTSKETCHSEGMENT", -0.002390499397973, 0.03694408160504, 0, false, 0, null, 0);

            swModel.EditSketch();

            // Delete an instance of the circular

            // sketch pattern and close the sketch

            boolstatus = swSketchMgr.EditCircularSketchStepAndRepeat(0.03184378021964, 4.732863934409, 3, 1.570796326795, true, "", true, true, true, "Line2_Line1_Line4_Line3_"

            );

            swModel.ClearSelection2(true);

            swSketchMgr.InsertSketch(true);

        }

        public SldWorks swApp;

    }

}



Provide feedback on this topic

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

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create and Edit Circular Sketch Pattern 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) 2010 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.