Insert Grid System Feature Example (C#)
This example shows how to insert a Grid System feature into a model.
//-----------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified Part template exists.
// 2. Ensure that the namespace matches your C# project name.
//
// Postconditions:
// 1. GridSystem1 is in the FeatureManager design tree.
// 2. GridSystem1 contains Surface-Extrude1, Level1, Level2,
//
and two
derived sketches.
// 3. The height of each level of the surface extrude is 50.0 mm.
//------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System;
using
System.Diagnostics;
namespace
InsertGridFeature_CSharp.csproj
{
partial
class
SolidWorksMacro
{
Feature
GridFeature;
ModelDoc2
Part;
ModelView
myModelView;
SketchSegment
skSegment;
bool
boolstatus;
int
longstatus;
public
void Main()
{
swApp.ResetUntitledCount(0, 0, 0);
Part = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SolidWorks
2011\\templates\\Part.prtdot", 0, 0, 0);
swApp.ActivateDoc2("Part1",
false,
ref
longstatus);
Part = (ModelDoc2)swApp.ActiveDoc;
myModelView = (ModelView)Part.ActiveView;
myModelView.FrameLeft = 0;
myModelView.FrameTop = 0;
myModelView.FrameState = (int)swWindowState_e.swWindowMaximized;
Part.ShowNamedView2("*Isometric",
7);
skSegment = Part.SketchManager.CreateCircle(-0.019633, 0.076084,
0.0, -0.001997, 0.081475, 0.0);
Part.SketchManager.InsertSketch(true);
boolstatus = Part.Extension.SelectByID2("Sketch1",
"SKETCH",
0, 0, 0, false,
0, null,
0);
object
offsetArray = null;
double[]
heightsArray = new
double[2];
heightsArray[0] = 0.05;
heightsArray[1] = 0.05;
offsetArray = heightsArray;
GridFeature = Part.FeatureManager.InsertGridFeature((offsetArray));
Debug.Print(GridFeature.Name
+ " was created.");
Part.ViewZoomtofit();
}
public
SldWorks
swApp;
}
}