// Define layer names and text size.
const double TextHeight = 2.5;
const string Dim = "Dimension", DashDot = "DashDot";
// Adding different layers
design1.Layers.Add(new Layer(Dim, Color.CornflowerBlue));
design1.Layers[0].LineWeight = 2;
design1.LineTypes.Add(DashDot, new float[] { 10, -2, 2, -2 });
Plane left = new Plane(Point3D.Origin, Vector3D.AxisY, -1 * Vector3D.AxisX); // plane.XY;
//Center hexagon
CompositeCurve hexagon = CompositeCurve.CreateHexagon(0, 0, 10, Math.PI / 2, true);
//Circle inside hexagon
Circle cr1 = new Circle(0, 0, 0, 10);
cr1.LineTypeName = DashDot;
cr1.LineTypeMethod = colorMethodType.byEntity;
//Center DashDot line of the image
Line l1 = new Line(-80, 0, 80, 0);
l1.LineTypeName = DashDot;
l1.LineTypeMethod = colorMethodType.byEntity;
//DashDot circle with diameter 25
Circle cr2 = new Circle(-50, -12.5, 0, 12.5);
cr2.LineTypeName = DashDot;
cr2.LineTypeMethod = colorMethodType.byEntity;
//X axis DashDot circle witch diameter 25
Line l2 = new Line(-65, -12.5, -35, -12.5);
l2.LineTypeName = DashDot;
l2.LineTypeMethod = colorMethodType.byEntity;
//Upper line of the figure
Line upperLine = new Line(-100, 15, 40, 15);
upperLine.Rotate(devDept.Geometry.Utility.DegToRad(30), Vector3D.AxisZ);
upperLine.TrimBy(l1.IntersectWith(upperLine)[0], true);
//Lower line of the figure
Line lowerLine = new Line(-100, -15, 40, -15);
lowerLine.Rotate(devDept.Geometry.Utility.DegToRad(30), Vector3D.AxisZ);
lowerLine.TrimBy(l1.IntersectWith(lowerLine)[0], false);
//Starting point for the upper line of the figure
Point3D[] startUpperLine = l1.IntersectWith(upperLine);
//Left tangent line to the circle with diameter 25
Line[] tgl;
devDept.Geometry.Utility.GetLinesTangentToCircleFromPoint(cr2, startUpperLine[0], out tgl);
Line tangentLeft = tgl[1];
Point3D[] intPoint1 = tangentLeft.IntersectWith(cr2);
//Vertical DashDot line of the circle with diameter 25
Line vertLineLeftCircle = new Line(-50, 5, -50, -30);
vertLineLeftCircle.LineTypeName = DashDot;
vertLineLeftCircle.LineTypeMethod = colorMethodType.byEntity;
//Vertical DashDot line of the hexagon
Line vertLineHex = new Line(0, 12, 0, -12);
vertLineLeftCircle.LineTypeName = DashDot;
vertLineLeftCircle.LineTypeMethod = colorMethodType.byEntity;
//copy1 is the mirrored on YZ axis tangentLeft clone
Line copy1 = (Line)tangentLeft.Clone();
Line copy2 = (Line)l1.Clone();
Plane planeYZ = Plane.YZ;
Plane planeXZ = Plane.XZ;
planeYZ.Translate(-50, 0);
planeXZ.Translate(-50, 0);
Transformation mirrorYZ = Transformation.CreateReflection(planeYZ);
Transformation mirrorXZ = Transformation.CreateReflection(planeXZ);
copy1.TransformBy(mirrorYZ);
copy2.TransformBy(mirrorXZ);
Point3D[] intPoint2 = copy1.IntersectWith(cr2);
ICurve[] tangentLeftMirror = copy1.Offset(9, Vector3D.AxisZ);
//Used to find the center of the circle with diameter 9
ICurve[] middleTangentLeftMirror = copy1.Offset(4.5, Vector3D.AxisZ);
ICurve[] l1Mirror = copy2.Offset(4.5, Vector3D.AxisZ);
Point3D[] cr9LeftCenter = l1Mirror[0].IntersectWith(middleTangentLeftMirror[0]);
//Circle with diameter 9
Circle cr9 = new Circle(cr9LeftCenter[0], 4.5);
copy1.TrimBy(cr9.IntersectWith(copy1)[0], true);
tangentLeftMirror[0].TrimBy(cr9.IntersectWith(tangentLeftMirror[0])[0], true);
//Top left arc of diameter 9
Arc a1 = new Arc(cr9.Center, cr9.Radius, Math.PI * 2);
a1.TrimBy(tangentLeftMirror[0].StartPoint, false);
a1.TrimBy(copy1.StartPoint, true);
//Bottom left arc of cr2
Arc a2 = new Arc(cr2.Center, cr2.Radius, Math.PI * 2);
a2.TrimBy(tangentLeft.EndPoint, false);
a2.TrimBy(copy1.EndPoint, true);
tangentLeftMirror[0].ExtendAt(50);
//Bottom arc of the figure of radius 26
Arc a2Bottom;
Curve.Fillet(tangentLeftMirror[0], lowerLine, 26, false, false, true, true, out a2Bottom);
tangentLeftMirror[0].TrimBy(a2Bottom.IntersectWith(tangentLeftMirror[0])[0], true);
lowerLine.TrimBy(a2Bottom.IntersectWith(tangentLeftMirror[0])[0], true);
//Intersect point between vert line starting from x=10 and upperLine to draw dimension
Line constDimLine = new Line(10, 0, 10, 50);//Vert line starting from x=10
Point3D[] dimLine = constDimLine.IntersectWith(upperLine);
Entity[] entitiesToMirror = new Entity[] { hexagon, cr1, cr2, l2, upperLine, lowerLine, tangentLeft, vertLineLeftCircle, copy1, (Entity)tangentLeftMirror[0], a1, a2, a2Bottom };
design1.Entities.Add(hexagon);
design1.Entities.Add(cr1, Dim);
design1.Entities.Add(l1, Dim);
design1.Entities.Add(cr2, Dim);
design1.Entities.Add(l2, Dim);
design1.Entities.Add(upperLine);
design1.Entities.Add(lowerLine);
design1.Entities.Add(tangentLeft);
design1.Entities.Add(vertLineLeftCircle, Dim);
design1.Entities.Add(vertLineHex, Dim);
design1.Entities.Add(copy1);
design1.Entities.Add((Entity)tangentLeftMirror[0]);
design1.Entities.Add(a1);
design1.Entities.Add(a2);
design1.Entities.Add(a2Bottom);
//for cycle to mirror every necessary entity on axis Y and X
foreach (Entity ent in entitiesToMirror)
{
Entity copy = (Entity)ent.Clone();
copy.Rotate(Math.PI, Vector3D.AxisZ);
design1.Entities.Add(copy);
}
Plane planexyR = Plane.XY;
planexyR.Rotate(devDept.Geometry.Utility.DegToRad(30), Vector3D.AxisZ);
planexyR.Rotate(devDept.Geometry.Utility.DegToRad(90), Vector3D.AxisZ);
planexyR.Rotate(devDept.Geometry.Utility.DegToRad(180), Vector3D.AxisZ);
Plane planexyR2 = Plane.XY;
planexyR2.Rotate(devDept.Geometry.Utility.DegToRad(26), Vector3D.AxisZ);
Point3D lowerIntPoint = l1.IntersectWith(lowerLine)[0];
design1.Entities.AddRange(new Entity[] {
new DiametricDim(cr2, new Point2D(-8, -8), TextHeight, Plane.XY),
new LinearDim(Plane.XY, new Point2D(-50, -30), new Point2D(50, -10), new Point2D(0, -50), TextHeight),
new LinearDim(planexyR, dimLine[0], lowerIntPoint, new Point3D(18, 10, 0), TextHeight),
new LinearDim(planexyR, new Point2D(-10, 5), new Point2D(10, 5), new Point2D(0, 14), TextHeight),
new RadialDim(a2Bottom, new Point2D(-25, -25), TextHeight, Plane.XY){ArrowsLocation = elementPositionType.Outside},
new AngularDim(Plane.XY, new Point2D(-50, -12.5), intPoint2[0], intPoint1[0], new Point2D(-50, -30), TextHeight),
new LinearDim(planexyR2, cr9.IntersectWith(copy1)[0], cr9.IntersectWith(tangentLeftMirror[0])[0], new Point3D(-80, 10, 0), TextHeight)
}, Dim);
// Center figure into frame
design1.Entities.Translate(105, 150);
design1.Entities.Regen();
DrawFrame();
// Top View
design1.SetView(viewType.Top);
design1.ZoomFit();
Print();
Frame drawing:
void DrawFrame()
{
const double height = 287;
const double width = 200;
const string FrameLayer = "FrameLayer";
design1.Layers.Add(new Layer(FrameLayer));
design1.Layers[FrameLayer].LineWeight = 2;
// Outer box
DrawMainBox(FrameLayer, height, width);
// Boxes with info
DrawInfoBox(FrameLayer, FrameLayer, width);
// Text within info boxes
DrawText("CAD Practice Drawing 900", width);
// Top box with number
DrawNumberBox(900, FrameLayer, FrameLayer, height, width);
}
void DrawMainBox(string frameLayerName, double height, double width)
{
Line line = new(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);
}
void DrawNumberBox(int number, string frameLayerName, string frameTextLayerName, double height, double width)
{
Line line = new(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(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(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);
}
void DrawText(string title, double width)
{
Text text = new(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);
}
Printing on A4 paper sheet:
private async void Print()
{
// A4 size in hundredth of inches
PaperSize paperSize = new System.Drawing.Printing.PaperSize("A4", 826, 1169);
design1.PageSetup(true, false, 0, paperSize, false);
// 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);
await design1.DoWorkAsync(hdl);
}
Comments
Please sign in to leave a comment.