// Define layer names and text size.
const string Dim = "Dimension", DashDot = "DashDot";
const double TextHeight = 5.0;
// 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 });
// Top hole
const double
holeInternDiameter = 28,
holeExternDiameter = 60,
holeY = 113;
Circle c0 = new Circle(0, holeY, 0, holeInternDiameter / 2);
Arc a0 = new Arc(0, holeY, 0, holeExternDiameter / 2, -Math.PI / 2, Math.PI * 1.5);
// Right
const double
rightX = 40,
rightY = 83,
rightRadius = 20;
Arc a1 = new Arc(rightX, rightY, 0, rightRadius, Math.PI / 2, Math.PI * 1.5);
Point3D a0a1Int = a0.IntersectWith(a1)[0];
a0.TrimBy(a0a1Int, true);
a1.TrimBy(a0a1Int, true);
// Bottom right
const double
bottomX = 6,
bottomRadius = 65,
bottomRightRadius = 46;
Arc a2 = new Arc(bottomX + bottomRadius - bottomRightRadius, 0, 0, bottomRightRadius, 0, Math.PI / 2);
Line a1toa2 = UtilityEx.GetLinesTangentToTwoCircles(a1, a2)[0];
a1.TrimBy(a1toa2.StartPoint, false);
a2.TrimBy(a1toa2.EndPoint, false);
Arc a3 = new Arc(bottomX, 0, 0, bottomRadius, Math.PI * 1.5, Math.PI * 2);
// Bottom
const double bottomInternalRadius = 25;
Arc a4 = new Arc(0, 0, 0, bottomInternalRadius, -Math.PI, Math.PI / 2);
Line a0toa4 = UtilityEx.GetLinesTangentToTwoCircles(a0, a4)[2];
a0.TrimBy(a0toa4.StartPoint, false);
a4.TrimBy(a0toa4.EndPoint, false);
// Bottom left
const double
bottomLeftY = -5,
bottomLeftRadius = 60;
Arc a5 = new Arc(bottomX, bottomLeftY, 0, bottomLeftRadius, Math.PI / 2, Math.PI * 1.5);
// Left
const double
leftX = -70,
leftPolarRadius = 37,
leftRadius = 8,
leftBigRadius = 45,
tangentCircleRadius = 45;
const double leftPolarAngle = Math.PI * 50 / 180;
Arc a6 = new Arc(leftX + leftPolarRadius * Math.Cos(leftPolarAngle), leftPolarRadius * Math.Sin(leftPolarAngle), 0, leftRadius, 0, Math.PI * 3 / 2);
Arc a7 = new Arc(leftX, 0, 0, leftBigRadius, 0, leftPolarAngle);
a6.TrimBy(a6.IntersectWith(a7)[0], true);
Circle c1 = UtilityEx.GetCirclesTangentToTwoCircles(a5, a6, tangentCircleRadius, true)[0];
a5.TrimBy(c1.StartPoint, true);
a6.TrimBy(c1.EndPoint, false);
design1.Entities.AddRange(new Entity[] { c0, a0, a1, a2, a1toa2, a3, a4, a0toa4, a5, a6, c1, a7 });
const double DimOffset = 10, AxisOverflow = 5;
Plane verticalDimensions = new Plane(Point3D.Origin, Vector3D.AxisY, -1 * Vector3D.AxisX);
Plane Rotation = (Plane)Plane.XY.Clone();
Rotation.Rotate(leftPolarAngle, Vector3D.AxisZ);
design1.Entities.AddRange(new Entity[]
{
// Linear dimensions
new LinearDim(Plane.XY, new Point2D(-holeInternDiameter / 2, holeY),
new Point2D(holeInternDiameter / 2, holeY), new Point2D(0, holeY + holeExternDiameter / 2 + DimOffset), TextHeight),
new LinearDim(Plane.XY, new Point2D(-holeExternDiameter / 2, holeY),
new Point2D(holeExternDiameter / 2, holeY), new Point2D(0, holeY + holeExternDiameter / 2 + 2 * DimOffset), TextHeight),
new LinearDim(verticalDimensions, new Point2D(0, 0),
new Point2D(holeY, 0), new Point2D(holeY / 2, -bottomX - bottomRadius - 2 * DimOffset), TextHeight),
new LinearDim(verticalDimensions, new Point2D(0, -rightX),
new Point2D(rightY, -rightX), new Point2D(rightY / 2, -bottomX - bottomRadius - DimOffset), TextHeight),
new LinearDim(Plane.XY, new Point2D(0, rightY),
new Point2D(rightX, rightY), new Point2D(rightX / 2, rightY - 2 * DimOffset), TextHeight),
new LinearDim(Rotation, new Point2D(leftX * Math.Cos(leftPolarAngle), -leftX * Math.Sin(leftPolarAngle)),
new Point2D(leftX * Math.Cos(leftPolarAngle) + leftPolarRadius, -leftX * Math.Sin(leftPolarAngle)),
new Point2D(leftX * Math.Cos(leftPolarAngle) + leftPolarRadius / 2, -leftX * Math.Sin(leftPolarAngle) + 2 * DimOffset), TextHeight),
new LinearDim(verticalDimensions, new Point2D(bottomLeftY, -bottomX), new Point2D(0, -bottomX),
new Point2D(bottomLeftY / 2, -bottomX - DimOffset), TextHeight),
new LinearDim(Plane.XY, new Point2D(0, 0), new Point2D(bottomX, 0), new Point2D(bottomX / 2, -4 * DimOffset), TextHeight),
new LinearDim(Plane.XY, new Point2D(leftX, 0), new Point2D(0, 0), new Point2D(leftX / 2, -bottomLeftRadius - DimOffset), TextHeight),
// Radial dimensions
new RadialDim(a1, new Point2D(-25, 10), TextHeight),
new RadialDim(a2, new Point2D(20, 10), TextHeight),
new RadialDim(a3, new Point2D(30, -30), TextHeight, Plane.XY),
new RadialDim(a4, new Point2D(-25, -30), TextHeight)
{
ArrowsLocation = elementPositionType.Outside
},
new RadialDim(a5, new Point2D(-20, -35), TextHeight),
new RadialDim(a6, new Point2D(10, 20), TextHeight, Plane.XY)
{
ArrowsLocation = elementPositionType.Outside
},
new RadialDim(c1, new Point2D(25, 5), TextHeight),
new RadialDim(a7, new Point2D(30, 10), TextHeight),
// Angular dimension
new AngularDim(Plane.XY, a7.Center, a7.StartPoint, a7.EndPoint, new Point2D(-10, 30), TextHeight)
{
ExtLineOffset = 0
}
}, Dim);
design1.Entities.AddRange(new Entity[] // axes
{
new Line(-holeExternDiameter / 2 - AxisOverflow, holeY, holeExternDiameter / 2 + AxisOverflow, holeY)
{
LineTypeMethod = colorMethodType.byEntity,
LineTypeName = DashDot
},
new Line(leftX - AxisOverflow, 0, bottomX + bottomRadius + AxisOverflow, 0)
{
LineTypeMethod = colorMethodType.byEntity,
LineTypeName = DashDot
},
new Line(0, holeY + holeExternDiameter / 2 + AxisOverflow, 0, -bottomRadius - AxisOverflow)
{
LineTypeMethod = colorMethodType.byEntity,
LineTypeName = DashDot
}
}, Dim);
// Center figure into frame
const double scale = 0.80;
design1.Entities.Scale(scale);
design1.Entities.Translate(100, 100);
foreach (Entity en in design1.Entities)
{
if (en is Dimension dm)
{
// Restore original measure
dm.LinearScale = 1 / scale;
}
}
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;
// drawing the ln1
Line ln1 = new Line(0, 0, width, 0);
design1.Entities.Add(ln1, FrameLayer);
ln1 = new Line(width, 0, width, height);
design1.Entities.Add(ln1, FrameLayer);
ln1 = new Line(width, height, 0, height);
design1.Entities.Add(ln1, FrameLayer);
ln1 = new Line(0, height, 0, 0);
design1.Entities.Add(ln1, FrameLayer);
}
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.