Split Open Sketch Segment Example (C#)
This example shows how to split an open sketch segment.
//---------------------------------------------------------------
// Preconditions: Open a part document.
//
// Postconditions:
// 1. A sketch is created.
// 2. A line segment is created.
// 3. The line segment is split into two segments.
//----------------------------------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System.Runtime.InteropServices;
using
System;
namespace
SplitOpenSegment_CSharp.csproj
{
partial
class
SolidWorksMacro
{
ModelDoc2
swModel;
SketchSegment
swSketchSegment;
object
skSegmentArray;
bool
boolstatus;
public
void Main()
{
swModel = (ModelDoc2)swApp.ActiveDoc;
boolstatus = swModel.Extension.SelectByID2("Front
Plane",
"PLANE", 0, 0, 0,
false, 0,
null, 0);
swModel.SketchManager.InsertSketch(true);
swModel.ClearSelection2(true);
// Create a line
swSketchSegment = swModel.SketchManager.CreateLine(-0.055964,
0.033212, 0.0, 0.102938, -0.014129, 0.0);
swModel.ViewZoomtofit2();
skSegmentArray = swModel.SketchManager.SplitOpenSegment(0.02,
0.01, 0.0);
// Close the sketch and rebuild
swModel.SketchManager.Insert3DSketch(true);
}
public
SldWorks
swApp;
}
}