const string Dim = "Dimension",
DashDotLarge = "DashDotLarge",
DashDotSmall = "DashDotSmall",
ThinLayer = "ThinLayer",
CenterLinesL = "CenterLinesLarge",
CenterLinesS = "CenterLinesSmall";
// Add new layers
design1.Layers.Add(new Layer(Dim, Color.CornflowerBlue));
design1.Layers[0].LineWeight = 2;
design1.LineTypes.Add(DashDotLarge, new float[] { 9, -2, 2, -2 });
design1.LineTypes.Add(DashDotSmall, new float[] { 8, -1, 2, -1 });
design1.Layers.Add(new Layer(ThinLayer));
design1.Layers.Add(new Layer(CenterLinesL, Color.CornflowerBlue, DashDotLarge));
design1.Layers.Add(new Layer(CenterLinesS, Color.CornflowerBlue, DashDotSmall));
// Circles
Circle circleCenter = new Circle(0, 0, 0, 18);
Circle circleLeft = new Circle(-45, 0, 0, 18);
Circle circleRight = new Circle(45, 0, 0, 18);
design1.Entities.AddRange(new Entity[]
{
circleCenter,
circleLeft,
circleRight
});
// Border
CompositeCurve border = CompositeCurve.CreateRectangle(0, 0, 144, 108, 0, true);
design1.Entities.Add(border, Color.Black);
// Rectangles
CompositeCurve rectangleLeft = CompositeCurve.CreateRectangle(-45, 40.5, 18, 9, 0, true);
CompositeCurve rectangleCenter = CompositeCurve.CreateRectangle(0, 40.5, 18, 9, 0, true);
CompositeCurve rectangleRight = CompositeCurve.CreateRectangle(45, 40.5, 18, 9, 0, true);
design1.Entities.AddRange(new Entity[]
{
rectangleLeft,
rectangleCenter,
rectangleRight
});
// UpDown
Line lineRight1 = new Line(-72, -36, -54, -36);
Line lineDown1 = new Line(-54, -36, -54, -45);
Line lineRight2 = new Line(-54, -45, -36, -45);
Line lineup1 = new Line(-36, -45, -36, -36);
Line lineRight3 = new Line(-36, -36, -9, -36);
Line lineDown2 = new Line(-9, -36, -9, -45);
Line lineRight4 = new Line(-9, -45, 9, -45);
Line lineup2 = new Line(9, -45, 9, -36);
Line lineRight5 = new Line(9, -36, 36, -36);
Line lineDown3 = new Line(36, -36, 36, -45);
Line lineRight6 = new Line(36, -45, 54, -45);
Line lineup3 = new Line(54, -45, 54, -36);
Line lineRight7 = new Line(54, -36, 72, -36);
design1.Entities.AddRange(new Entity[]
{
lineRight1,
lineDown1,
lineRight2,
lineup1,
lineRight3,
lineDown2,
lineRight4,
lineup2,
lineRight5,
lineDown3,
lineRight6,
lineup3,
lineRight7
});
// Add new dimension plane
Plane pln = new Plane(Point3D.Origin, Vector3D.AxisY, Vector3D.AxisMinusX);
double textSize = 3.5;
// Linear dimensions
design1.Entities.AddRange(new Entity[]
{
new LinearDim(Plane.XY, new Point2D(-72, 54), new Point2D(-45, 54), new Point2D(-58.5, 64), textSize),
new LinearDim(Plane.XY, new Point2D(-45, 54), new Point2D(0, 59), new Point2D(-22.5, 64), textSize),
new LinearDim(Plane.XY, new Point2D(0, 59), new Point2D(45, 54), new Point2D(22.5, 64), textSize),
new LinearDim(Plane.XY, new Point2D(-54, 37.5), new Point2D(-36, 37.5), new Point2D(-45, 27.5), textSize),
new LinearDim(Plane.XY, new Point2D(-72, -45), new Point2D(-54, -45), new Point2D(-63, -64), textSize),
new LinearDim(Plane.XY, new Point2D(-54, -45), new Point2D(-36, -45), new Point2D(-45, -64), textSize),
new LinearDim(Plane.XY, new Point2D(-36, -45), new Point2D(-9, -45), new Point2D(-22.5, -64), textSize),
new LinearDim(Plane.XY, new Point2D(-72, -54), new Point2D(72, -54), new Point2D(0, -73), textSize),
new LinearDim(pln, new Point2D(-54, 72), new Point2D(54, 72), new Point2D(0, 92), textSize),
new LinearDim(pln, new Point2D(-54, 72), new Point2D(-36, 72), new Point2D(-45, 82), textSize),
new LinearDim(pln, new Point2D(-36, 72), new Point2D(0, 72), new Point2D(-18, 82), textSize),
new LinearDim(pln, new Point2D(0, 65), new Point2D(40.5, 56), new Point2D(20.25, 82), textSize),
new LinearDim(pln, new Point2D(-45, 54), new Point2D(-36, 54), new Point2D(-40.5, 59), textSize),
new LinearDim(pln, new Point2D(45, 36), new Point2D(36, 36), new Point2D(49.5, 31), textSize)
}, Dim);
// Diametric dimension
design1.Entities.Add(new DiametricDim(circleRight, new Point2D(12, 24), textSize)
{
ArrowsLocation = elementPositionType.Inside,
LineTypeMethod = colorMethodType.byEntity,
TextPrefix = "Ø",
}, Dim);
// Center lines
Line Xcircles = new Line(-64, 0, 64, 0);
Line YLeftcircles = new Line(-45, -19, -45, 19);
Line YCentercircles = new Line(0, 19, 0, -49.5);
Line YRightcircles = new Line(45, -19, 45, 19);
design1.Entities.AddRange(new Entity[]
{
Xcircles,
YLeftcircles,
YCentercircles,
YRightcircles,
}, CenterLinesL);
Line Xrectangle1 = new Line(-55, 40.5, -22, 40.5);
Line Xrectangle2 = new Line(-22, 40.5, 22, 40.5);
Line Xrectangle3 = new Line(23, 40.5, 55, 40.5);
Line Yrectangle1 = new Line(-45, 18.5, -45, 46);
Line Yrectangle2 = new Line(0, 62.5, 0, 20);
Line Yrectangle3 = new Line(45, 18.5, 45, 46);
design1.Entities.AddRange(new Entity[]
{
Xrectangle1,
Xrectangle2,
Xrectangle3,
Yrectangle1,
Yrectangle2,
Yrectangle3
}, CenterLinesS);
// Scales the line type pattern
foreach (LineType lt in design1.LineTypes)
{
for (int i = 0; i < lt.Pattern.Length; i++)
{
lt.Pattern[i] *= 2;
}
}
// Scales and centers the drawing
design1.Entities.Scale(2);
design1.Entities.Translate(20, 0);
// Change dimensions linear scale
foreach (Entity entity in design1.Entities)
{
if (entity is Dimension dim)
{
dim.LinearScale = 0.5;
}
}
// Regenerates the entities
design1.Entities.Regen();
DrawFrame();
// Sets top view
design1.SetView(viewType.Top);
// Fits the model in the viewport
design1.ZoomFit();
Print();
void DrawFrame()
{
const string ThinLayer = "ThinLayer";
string frameID = "63";
string frameTitle = "CAD Practice Drawing " + frameID;
int halfWidth = 200;
int halfHeight = 287;
design1.Entities.AddRange(new Entity[] {
new LinearPath(-halfWidth, -halfHeight, 2 * halfWidth, 2 * halfHeight),
new Line(-halfWidth / 4, -halfHeight + 30, halfWidth, -halfHeight + 30),
new Line(-halfWidth / 4, -halfHeight + 30, -halfWidth / 4, -halfHeight),
new Text(25, -halfHeight + 25, 0, "Title", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
new Text(25, -halfHeight + 10, 0, frameTitle, 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
new Text(115, -halfHeight + 25, 0, "Date", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
new Text(115, -halfHeight + 15, 0, "Design", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
new Text(115, -halfHeight + 5, 0, "Check", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
new Text(180, -halfHeight + 25, 0, "Approve", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
new Line(halfWidth - 30, halfHeight - 15, halfWidth, halfHeight - 15),
new Line(halfWidth - 30, halfHeight - 15, halfWidth - 30, halfHeight),
new Text(halfWidth - 15, halfHeight - 7.5, 0, frameID, 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter)
});
// Add thin lines
design1.Entities.AddRange(new Entity[] {
new Line(-halfWidth / 4, -halfHeight + 20, halfWidth, -halfHeight + 20),
new Line(100, -halfHeight + 30, 100, -halfHeight),
new Line(130, -halfHeight + 30, 130, -halfHeight),
new Line(160, -halfHeight + 30, 160, -halfHeight),
new Line(100, -halfHeight + 10, 160, -halfHeight + 10)
}, ThinLayer);
}
private void Print()
{
design1.PageSetup(true, false, 0, new System.Drawing.Printing.PaperSize("A4", 826, 1169), false);
//Save current view Camera
design1.SaveView(out Camera cameraSaved);
design1.ActiveViewport.Camera.ProjectionMode = devDept.Eyeshot.projectionType.Orthographic;
//Creates printing setting object and customize it
HiddenLinesViewSettingsEx hdlS = new HiddenLinesViewSettingsEx(design1, hiddenLinesViewType.Viewport);
hdlS.KeepEntityLineWeight = true;
//Creates paper preview
HiddenLinesViewOnPaperPreview hdl = new HiddenLinesViewOnPaperPreview(hdlS, new Size(800, 600), 0.5);
design1.StartWork(hdl);
//Restore saved view
design1.RestoreView(cameraSaved);
}
Comments
Please sign in to leave a comment.