protected override void OnLoad(EventArgs e)
{
const string Dim = "Dimension", DashDot = "DashDot";
const double TextHeight = 4;
design1.Layers.Add(new Layer(Dim, Color.CornflowerBlue));
design1.Layers.Add(new Layer("framelayer"));
design1.Layers.Add(new Layer("framelayertext"));
design1.Layers.Add(new Layer("Hatch"));
design1.Layers["Default"].LineWeight = 2;
design1.Layers["framelayer"].LineWeight = 2;
design1.LineTypes.Add(DashDot, new float[] { 5, -1, 1, -1 });
Line axisX = new Line(-40, 0, 100, 0);
axisX.LineTypeMethod = colorMethodType.byEntity;
axisX.LineTypeName = DashDot;
design1.Entities.Add(axisX, Dim);
Line axisY = new Line(0, -40, 0, 100);
axisY.LineTypeMethod = colorMethodType.byEntity;
axisY.LineTypeName = DashDot;
design1.Entities.Add(axisY, Dim);
// used for vertical linearDim
Plane left = new Plane(Point3D.Origin, Vector3D.AxisY, -1 * Vector3D.AxisX);
Circle circleE5 = new Circle(0, 0, 0, 6.5);
DiametricDim dDim1 = new DiametricDim(circleE5, new Point2D(-20, 20), TextHeight);
design1.Entities.Add(dDim1, Dim);
Arc arcE5 = new Arc(0, 0, 0, 13, Utility.DegToRad(78), Utility.DegToRad(270));
RadialDim rDim1 = new RadialDim(arcE5, new Point2D(-25, -25), TextHeight)
{
ArrowsLocation = elementPositionType.Outside,
};
design1.Entities.Add(rDim1, Dim);
Line lineC5 = new Line(128.5, 0, 102.5, 0);
Arc arcC5 = new Arc(128.5, 33, 0, 33, -Math.PI / 2, Math.PI / 2);
RadialDim rDim2 = new RadialDim(arcC5, new Point2D(20, 8), TextHeight)
{
CenterMarkSize = 3
};
design1.Entities.Add(rDim2, Dim);
Line lineC6 = new Line(128.5, 66, 115.5, 66);
Arc arcC6 = new Arc(115.5, 74, 0, 8, Math.PI / 2, Math.PI * 3 / 2);
RadialDim rDim3 = new RadialDim(arcC6, new Point2D(-20, 10), TextHeight)
{
CenterMarkSize = 10,
ArrowsLocation = elementPositionType.Outside
};
design1.Entities.Add(rDim3, Dim);
Line lineC7 = new Line(128.5, 82, 115.5, 82);
Arc arcC5_Rad54 = new Arc(128.5, 28, 0, 54, Utility.DegToRad(-110), Math.PI / 2);
RadialDim rDim4 = new RadialDim(arcC5_Rad54, new Point2D(20, -8), TextHeight)
{
CenterMarkSize = 5
};
design1.Entities.Add(rDim4, Dim);
Arc arcE5_Rad205 = new Arc(19, 30, 0, 20.5, Utility.DegToRad(-90 - 12), Utility.DegToRad(90 - 12));
RadialDim rDim5 = new RadialDim(arcE5_Rad205, new Point2D(45, 35), TextHeight)
{
CenterMarkSize = 5,
ArrowsLocation = elementPositionType.Outside,
};
design1.Entities.Add(rDim5, Dim);
Arc arcCc6E = new Arc(6, 58.5, 0, 8, Math.PI / 2, Math.PI * 3 / 2);
CompositeCurve cc6E = new CompositeCurve(new ICurve[] {
new Line(19, 66.5, 6, 66.5),
arcCc6E,
new Line(6, 50.5, 19, 50.5)}, false);
cc6E.Rotate(Utility.DegToRad(-12), Vector3D.AxisZ, new Point3D(19, 30, 0));
RadialDim rDim6 = new RadialDim((Arc)cc6E.CurveList[1], 24, Utility.DegToRad(150), TextHeight, Plane.XY);
rDim6.CenterMarkSize = 3;
rDim6.ArrowsLocation = elementPositionType.Outside;
design1.Entities.Add(rDim6, Dim);
List<Entity> linesE3 = new List<Entity>(){
new Line(25.5, -44, 63.5, -44),
new Line(25.5, -56, 63.5, -56),
new Line(25.5, -66, 63.5, -66),
new Line(25.5, -40, 25.5, -64),
new Line(63.5, -20, 63.5, -64)};
foreach (var line in linesE3)
{
design1.Entities.Add(line);
}
CompositeCurve ccHatchUp = new CompositeCurve(
new Line(25.5, -44, 63.5, -44),
new Line(25.5, -44, 25.5, -40),
new Line(25.5, -40, 33, -38.5),
new Line(33, -38.5, 45.5, -33),
new Line(45.5, -33, 54, -36),
new Line(54, -36, 63.5, -35),
new Line(63.5, -35, 63.5, -44)
);
design1.Entities.Add(ccHatchUp, Dim);
Arc filletE3Left;
Curve.Fillet((Line)linesE3[3], (Line)linesE3[2], 5, false, false, true, true, out filletE3Left);
Arc filletE3Right;
Curve.Fillet((Line)linesE3[4], (Line)linesE3[2], 5, true, false, true, true, out filletE3Right);
design1.Entities.Add(filletE3Left);
design1.Entities.Add(filletE3Right);
CompositeCurve ccHatchDown = new CompositeCurve(
filletE3Left,
filletE3Right,
(Line)linesE3[2],
new Line(filletE3Left.StartPoint, ((Line)linesE3[1]).StartPoint),
(Line)linesE3[1],
new Line(((Line)linesE3[1]).EndPoint, filletE3Right.StartPoint)
);
HatchPatternLine hpl = new HatchPatternLine(Utility.DegToRad(45 + 20), Point2D.Origin, 0, 4, new float[0]);
HatchPattern hp = new HatchPattern("continuos", new[] { hpl });
design1.HatchPatterns.Add(hp);
Hatch hatchUp = new Hatch(hp.Name, ccHatchUp);
Hatch hatchDown = new Hatch(hp.Name, ccHatchDown);
design1.Entities.Add(hatchUp, Dim);
design1.Entities.Add(hatchDown, Dim);
linesE3.Add(ccHatchUp);
linesE3.Add(filletE3Left);
linesE3.Add(filletE3Right);
linesE3.Add(ccHatchDown);
linesE3.Add(hatchUp);
linesE3.Add(hatchDown);
// rotate everything in the list
foreach (var line in linesE3)
{
line.Rotate(Utility.DegToRad(-20), Vector3D.AxisZ, new Point3D(0, -40, 0));
}
RadialDim rDim10 = new RadialDim(filletE3Left, 24, Utility.DegToRad(190), TextHeight, Plane.XY);
rDim10.CenterMarkSize = 0;
rDim10.ArrowsLocation = elementPositionType.Outside;
design1.Entities.Add(rDim10, Dim);
Line axisLinesE3 = new Line(15.5, -50, 73.5, -50);
axisLinesE3.LineTypeMethod = colorMethodType.byEntity;
axisLinesE3.LineTypeName = DashDot;
axisLinesE3.Rotate(Utility.DegToRad(-20), Vector3D.AxisZ, new Point3D(0, -40, 0));
design1.Entities.Add(axisLinesE3, Dim);
LinearDim lDim1 = new LinearDim(Plane.XY, new Point2D(25.5, -66), new Point2D(63.5, -66), new Point2D(44.5, -89.4), TextHeight);
lDim1.Rotate(Utility.DegToRad(-20), Vector3D.AxisZ, new Point3D(0, -40, 0));
design1.Entities.Add(lDim1, Dim);
LinearDim lDim2 = new LinearDim(left, new Point2D(-44, -25.5), new Point2D(-56, -25.5), new Point2D(-50, -13), TextHeight);
lDim2.Rotate(Utility.DegToRad(-20), Vector3D.AxisZ, new Point3D(0, -40, 0));
design1.Entities.Add(lDim2, Dim);
LinearDim lDim3 = new LinearDim(left, new Point2D(-66, -63.5), new Point2D(-50, -63.5), new Point2D(-58, -85.5), TextHeight);
lDim3.Rotate(Utility.DegToRad(-20), Vector3D.AxisZ, new Point3D(0, -40, 0));
design1.Entities.Add(lDim3, Dim);
Arc arcE4 = new Arc(0, -40, 0, 25.5, Utility.DegToRad(-20), Utility.DegToRad(90));
RadialDim rDim7 = new RadialDim(arcE4, new Point2D(35, 25), TextHeight)
{
CenterMarkSize = 5,
ArrowsLocation = elementPositionType.Outside,
};
design1.Entities.Add(rDim7, Dim);
Line connectArcE4ArcE5 = Utility.GetLinesTangentToTwoCircles(arcE4, arcE5)[0];
design1.Entities.Add(connectArcE4ArcE5);
arcE4.TrimBy(connectArcE4ArcE5.StartPoint, false);
arcE5.TrimBy(connectArcE4ArcE5.EndPoint, false);
Line connectArcE5ArcE5arcE5_Rad205 = new Line(arcE5.StartPoint, arcE5_Rad205.StartPoint);
Arc arcE5_Rad365 = new Arc(19, 30, 0, 36.5, Utility.DegToRad(-12), Utility.DegToRad(90 - 12));
Arc filletD6;
Curve.Fillet(arcE5_Rad365, lineC5, 50, true, true, true, true, out filletD6);
RadialDim rDim8 = new RadialDim(filletD6, filletD6.Radius / 2, Utility.DegToRad(210), TextHeight, Plane.XY);
rDim8.CenterMarkSize = 5;
design1.Entities.Add(rDim8, Dim);
Arc filletD3;
Curve.Fillet((Line)linesE3[4], arcC5_Rad54, 50, false, true, true, true, out filletD3);
RadialDim rDim9 = new RadialDim(filletD3, 30, Utility.DegToRad(115), TextHeight, Plane.XY);
rDim9.CenterMarkSize = 0;
design1.Entities.Add(rDim9, Dim);
design1.Entities.Add(circleE5);
design1.Entities.Add(arcE5);
design1.Entities.Add(lineC5);
design1.Entities.Add(arcC5);
design1.Entities.Add(lineC6);
design1.Entities.Add(arcC6);
design1.Entities.Add(lineC7);
design1.Entities.Add(arcC5_Rad54);
design1.Entities.Add(arcE5_Rad205);
design1.Entities.Add(cc6E);
design1.Entities.Add(arcE4);
design1.Entities.Add(connectArcE5ArcE5arcE5_Rad205);
design1.Entities.Add(arcE5_Rad365);
design1.Entities.Add(filletD6);
design1.Entities.Add(filletD3);
design1.Entities.Add(new LinearDim(Plane.XY, new Point2D(0, 0), new Point2D(128.5, 33), new Point2D(128.5 / 2, 100), TextHeight), Dim);
design1.Entities.Add(new LinearDim(Plane.XY, new Point2D(115.5, 66 + 16), new Point2D(128.5, 66 + 16), new Point2D(128.5 - 6.5, 90), TextHeight), Dim);
design1.Entities.Add(new LinearDim(Plane.XY, new Point2D(0, 30), new Point2D(19, 30), new Point2D(19.0 / 2, 20), TextHeight), Dim);
LinearDim deg12Rot = new LinearDim(Plane.XY, new Point2D(6, 30), new Point2D(19, 30), new Point2D(12.5, 80), TextHeight);
deg12Rot.Rotate(Utility.DegToRad(-12), Vector3D.AxisZ, new Point3D(19, 30, 0));
design1.Entities.Add(deg12Rot, Dim);
design1.Entities.Add(new LinearDim(left, new Point2D(0, -128.5), new Point2D(33, -128.5), new Point2D(33.0 / 2, -100), TextHeight), Dim);
design1.Entities.Add(new LinearDim(left, new Point2D(0, -128.5), new Point2D(28, -128.5), new Point2D(28.0 / 2, -110), TextHeight), Dim);
design1.Entities.Add(new LinearDim(left, new Point2D(0, 0), new Point2D(30, 0), new Point2D(30.0 / 2, 40), TextHeight), Dim);
design1.Entities.Add(new LinearDim(left, new Point2D(0, 0), new Point2D(-40, 0), new Point2D(-30.0 / 2, 40), TextHeight), Dim);
design1.Entities.Add(new LinearDim(left, new Point2D(-71, -58), new Point2D(0, -71), new Point2D(-45, -80), TextHeight), Dim);
Line lTemp = new Line(39, 0, 39, -1);
lTemp.Rotate(Utility.DegToRad(-20), Vector3D.AxisZ, new Point3D(0, 0));
AngularDim angDim1 = new AngularDim(Plane.XY, new Line(0, 0, -1, 0), lTemp, new Point3D(-1, -1), new Point3D(-40, -60), TextHeight);
angDim1.ShowExtLine2 = false;
angDim1.Translate(0.19, 0);
design1.Entities.Add(angDim1, Dim);
Line lTemp2 = new Line(19, 30, 19, 31);
lTemp2.Rotate(Utility.DegToRad(90 - 12), Vector3D.AxisZ, new Point3D(19, 30));
AngularDim angDim2 = new AngularDim(Plane.XY, new Line(19, 30, 18, 30), lTemp2, new Point3D(-999, 31), new Point3D(-40, 36), TextHeight);
design1.Entities.Add(angDim2, Dim);
double scale = 0.70;
design1.Entities.Scale(scale);
design1.Entities.Translate(100, 110);
foreach (Entity en in design1.Entities)
{
if (en is Dimension)
{
// Restore original measure
((Dimension)en).LinearScale = 1 / scale;
}
}
design1.Entities.Regen();
design1.Entities.RegenAllCurved(0.001);
DrawFrame();
design1.SetView(viewType.Top, true, false);
design1.ZoomFit();
Print();
}
void DrawFrame()
{
const string frameLayerName = "Frame", frameTextLayerName = "FrameText";
design1.Layers.Add(new Layer(frameLayerName) { LineWeight = 2 });
design1.Layers.Add(new Layer(frameTextLayerName));
double height = 200, width = 287; // A4 landscape
// double height = 287, width = 200; // A4 portrait
// drawing the outer box
DrawMainBox(frameLayerName, height, width);
// drawing boxes with info
DrawInfoBox(frameLayerName, frameTextLayerName, width);
// writing text in the info boxes
DrawText("2D CAD drawing practice", width);
// drawing top box with number in it
DrawNumberBox(1, frameLayerName, frameTextLayerName, height, width);
}
private void DrawMainBox(string frameLayerName, double height, double width)
{
Line line = new Line(0, height, width, height);
design1.Entities.Add(line, frameLayerName);
line = new Line(0, height, 0, 0);
design1.Entities.Add(line, frameLayerName);
line = new Line(0, 0, width, 0);
design1.Entities.Add(line, frameLayerName);
line = new Line(width, 0, width, height);
design1.Entities.Add(line, frameLayerName);
}
private void DrawNumberBox(int number, string frameLayerName, string frameTextLayerName, double height, double width)
{
Line line = new Line(width - 13, height - 7, width, height - 7);
design1.Entities.Add(line, frameLayerName);
line = new Line(width - 13, height, width - 13, height - 7);
design1.Entities.Add(line, frameLayerName);
Text text = new Text(width - 6.75, height - 3.5, 0, number.ToString(), 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text, frameTextLayerName);
}
private void DrawInfoBox(string frameLayerName, string frameTextLayerName, double width)
{
Line line = new Line(width - 160, 0, width - 160, 20);
design1.Entities.Add(line, frameLayerName);
line = new Line(width - 160, 20, width, 20);
design1.Entities.Add(line, frameLayerName);
// Using frameTextLayerName to have thinner lines
line = new Line(width - 65, 0, width - 65, 20);
design1.Entities.Add(line, frameTextLayerName);
line = new Line(width - 160, 13, width, 13);
design1.Entities.Add(line, frameTextLayerName);
line = new Line(width - 45, 0, width - 45, 20);
design1.Entities.Add(line, frameTextLayerName);
line = new Line(width - 25, 0, width - 25, 20);
design1.Entities.Add(line, frameTextLayerName);
line = new Line(width - 65, 7, width - 25, 7);
design1.Entities.Add(line, frameTextLayerName);
}
private void DrawText(string title, double width)
{
Text text = new Text(width - 112, 16.5, 0, "Title", 3, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
text = new Text(width - 112, 7, 0, title, 4.5, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
text = new Text(width - 55, 16.5, 0, "Date", 3, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
text = new Text(width - 55, 10, 0, "Design", 3, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
text = new Text(width - 55, 3.5, 0, "Check", 3, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
text = new Text(width - 12.5, 16.5, 0, "Approve", 3, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
}
private void Print()
{
// A4 size in hundredth of inches
PaperSize paperSize = new System.Drawing.Printing.PaperSize("A4", 826, 1169);
design1.PageSetup(true, false, 0, paperSize, true);
// creates printing setting object and customize it
HiddenLinesViewSettingsEx hdlS = new HiddenLinesViewSettingsEx(viewType.Top, design1.Document);
hdlS.KeepEntityLineWeight = true;
// creates paper preview
const double printScaling = 1;
HiddenLinesViewOnPaperPreview hdl = new HiddenLinesViewOnPaperPreview(hdlS, new Size(800, 600), printScaling);
design1.StartWork(hdl);
}
Comments
Please sign in to leave a comment.