This example shows how to replace a sketch entity in a model with another
sketch entity.
//----------------------------------------------------------------------------
// Preconditions: Verify that the specified template exists.
//
// Postconditions:
// 1. Opens a new part and creates
Boss-Extrude1.
// 2. Replaces a sketch line with a sketch arc and modifies
// Boss-Extrude1.
// 3. Examine the graphics area.
//
---------------------------------------------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System.Runtime.InteropServices;
using
System;
namespace
ReplaceSketch_CSharp.csproj
{
partial
class
SolidWorksMacro
{
ModelDoc2
Part;
Feature
myFeature;
SketchSegment
skSegment;
bool
boolstatus;
public
void Main()
{
Part = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS
2017\\templates\\Part.prtdot", 0, 0, 0);
Part = (ModelDoc2)swApp.ActiveDoc;
boolstatus = Part.Extension.SelectByID2("Front
Plane",
"PLANE", -0.048646278525398,
0.0222864804840025, 0.0105288722478765,
false, 0,
null, 0);
object
vSkLines = null;
vSkLines = Part.SketchManager.CreateCornerRectangle(-0.0338155129850894,
0.0167825138518592, 0, 0.0551067619016271, -0.0245475575743612, 0);
Part.ClearSelection2(true);
Part.SketchManager.InsertSketch(true);
Part.ShowNamedView2("*Trimetric",
8);
boolstatus = Part.Extension.SelectByID2("Sketch1",
"SKETCH",
0, 0, 0, false,
4, null,
0);
myFeature = Part.FeatureManager.FeatureExtrusion2(true,
false,
false, 0,
0, 0.01778, 0.00254, false,
false,
false,
false,
0.0174532925199433, 0.0174532925199433,
false,
false,
false,
false, true,
true,
true,
0, 0, false);
boolstatus = Part.Extension.SelectByID2("Sketch1",
"SKETCH",
0, 0, 0, false,
0, null,
0);
Part.EditSketch();
Part.ClearSelection2(true);
skSegment = Part.SketchManager.Create3PointArc(-0.033816,
0.016783, 0.0, 0.055107, 0.016783, 0.0, 0.016009, 0.025458, 0.0);
Part.ClearSelection2(true);
boolstatus = Part.Extension.SelectByID2("Line1",
"SKETCHSEGMENT",
0.00202904300411839, 0.0119654152286464, -0.00709549576220667,
true, 0,
null, 0);
boolstatus = Part.Extension.SelectByID2("Arc1",
"SKETCHSEGMENT",
0.00588878331207997, 0.0171023327681304, -0.0126221740799126,
true, 0,
null, 0);
boolstatus = Part.SketchManager.SketchReplace(true);
Part.SketchManager.InsertSketch(true);
}
public
SldWorks
swApp;
}
}