This article explains the fundamentals of 2D drawing and 1:2 scale paper printing.
private const string Dim = "Dimension", Lw05 = "Lw05";
private const string DashDot = "DashDot";
protected override void OnLoad(EventArgs e)
{
// set layers and linetype
design1.Layers[0].LineWeight = 2;
design1.Layers.Add(new Layer(Dim, Color.CornflowerBlue));
design1.Layers.Add(new Layer(Lw05));
design1.LineTypes.Add("DashDot", new float[] { 30, -5, 5, -5 });
// X and Y axes
Line axisX = new Line(-170, 0, 150, 0);
axisX.LineTypeMethod = colorMethodType.byEntity;
axisX.LineTypeName = DashDot;
design1.Entities.Add(axisX, Dim);
Line axisY = new Line(0, -150, 0, 170);
axisY.LineTypeMethod = colorMethodType.byEntity;
axisY.LineTypeName = DashDot;
design1.Entities.Add(axisY, Dim);
// center circle
Circle centerCircle = new Circle(0, 0, 0, 40);
design1.Entities.Add(centerCircle);
DiametricDim diamDimCC = new DiametricDim(centerCircle, new Point2D(20, 20), 8);
design1.Entities.Add(diamDimCC, Dim);
// screw holes circles
Circle shCircle = new Circle(0, 0, 0, 52);
shCircle.LineTypeMethod = colorMethodType.byEntity;
shCircle.LineTypeName = DashDot;
design1.Entities.Add(shCircle, Dim);
DiametricDim diamDimSC = new DiametricDim(shCircle, new Point2D(-160, -40), 8);
design1.Entities.Add(diamDimSC, Dim);
Circle smallCircle = new Circle(0, 52, 0, 5);
for (int i = 0; i < 6; i++)
{
Circle circle = (Circle)smallCircle.Clone();
circle.Rotate((Math.PI / 3) * i, Vector3D.AxisZ);
design1.Entities.Add(circle);
}
DiametricDim diamDimSmallCircle = new DiametricDim(new Circle(0, -52, 0, 5), new Point2D(-10, 20), 8);
design1.Entities.Add(diamDimSmallCircle, Dim);
//six composite curve
Arc arc = new Arc(0, 0, 0, 113, (Math.PI / 3), (Math.PI * 2 / 3));
design1.Entities.Add(new Arc(arc.Center, 113, devDept.Geometry.Utility.DegToRad(45), devDept.Geometry.Utility.DegToRad(70)), Dim);
Line line1 = new Line(-45, 113, -45, 0);
Line line2 = new Line(-45, 49, 55, 49);
line2.Rotate(devDept.Geometry.Utility.DegToRad(30), Vector3D.AxisZ, new Point3D(-45, 49));
design1.Entities.Add((Line)line2.Clone(), Dim);
Arc arcFillet1, arcFillet2, arcFillet3;
Curve.Fillet(arc, line1, 9.5, false, false, true, true, out arcFillet1);
Curve.Fillet(arc, line2, 9.5, false, false, true, true, out arcFillet2);
Curve.Fillet(line1, line2, 9.5, false, false, true, true, out arcFillet3);
CompositeCurve compositeCurve = new CompositeCurve(arc, line1, line2, arcFillet1, arcFillet2, arcFillet3);
for (int i = 0; i < 6; i++)
{
CompositeCurve compCurve = (CompositeCurve)compositeCurve.Clone();
compCurve.Rotate((Math.PI / 3) * i, Vector3D.AxisZ);
design1.Entities.Add(compCurve);
}
RadialDim rDim = new RadialDim(arc, new Point2D(65, 145), 8)
{
ArrowsLocation = elementPositionType.Outside,
TrimLeader = true,
CenterMarkSize = 0
};
design1.Entities.Add(rDim, Dim);
AngularDim angDim = new AngularDim(Plane.XY, axisX, line2, new Point3D(160, 60, 0), new Point3D(140, 80, 0), 8);
angDim.TextSuffix = "°";
design1.Entities.Add(angDim, Dim);
// arcFillet dimension
Arc copy = (Arc)arcFillet1.Clone();
copy.Rotate(devDept.Geometry.Utility.DegToRad(250), Vector3D.AxisZ, copy.Plane.Origin);
rDim = new RadialDim(copy, new Point2D(-40, 40), 8)
{
ArrowsLocation = elementPositionType.Outside,
TrimLeader = true,
CenterMarkSize = 0
};
design1.Entities.Add(rDim, Dim);
copy = (Arc)arcFillet2.Clone();
copy.Rotate(devDept.Geometry.Utility.DegToRad(280), Vector3D.AxisZ, copy.Plane.Origin);
rDim = new RadialDim(copy, new Point2D(15, 50), 8)
{
ArrowsLocation = elementPositionType.Outside,
TrimLeader = true,
CenterMarkSize = 0
};
design1.Entities.Add(rDim, Dim);
copy = (Arc)arcFillet3.Clone();
copy.Rotate(devDept.Geometry.Utility.DegToRad(180), Vector3D.AxisZ, copy.Plane.Origin);
rDim = new RadialDim(copy, new Point2D(10, 10), 8)
{
ArrowsLocation = elementPositionType.Outside,
TrimLeader = true
};
design1.Entities.Add(rDim, Dim);
design1.Entities.Add(new Arc(copy.Center, 9.5, Math.PI / 2), Dim);
// Teeth
DrawTeeth();
// Linear Dimension
Plane dim1Plane = new Plane(Point3D.Origin, Vector3D.AxisY, -1 * Vector3D.AxisX);//Plane.XY;
design1.Entities.Add(new LinearDim(dim1Plane, new Point2D(0, 160), new Point2D(49, 45), new Point2D(25, 170), 8), Dim);
design1.Entities.Add(new LinearDim(Plane.XY, new Point2D(-45, 49), new Point2D(0, 160), new Point2D(-22, 170), 8), Dim);
// Drawing frame
int halfWidth = 200;
int halfHeight = 287;
LinearPath lp = new LinearPath(-halfWidth, -halfHeight, 2 * halfWidth, 2 * halfHeight);
design1.Entities.Add(lp);
Line line = new Line(-halfWidth / 4, -halfHeight + 30, halfWidth, -halfHeight + 30);
design1.Entities.Add(line);
line = new Line(-halfWidth / 4, -halfHeight + 30, -halfWidth / 4, -halfHeight);
design1.Entities.Add(line);
line = new Line(-halfWidth / 4, -halfHeight + 20, halfWidth, -halfHeight + 20);
design1.Entities.Add(line, Lw05);
line = new Line(100, -halfHeight + 30, 100, -halfHeight);
design1.Entities.Add(line, Lw05);
line = new Line(130, -halfHeight + 30, 130, -halfHeight);
design1.Entities.Add(line, Lw05);
line = new Line(160, -halfHeight + 30, 160, -halfHeight);
design1.Entities.Add(line, Lw05);
line = new Line(100, -halfHeight + 10, 160, -halfHeight + 10);
design1.Entities.Add(line, Lw05);
Text text = new Text(25, -halfHeight + 25, 0, "Title", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
text = new Text(25, -halfHeight + 10, 0, "CAD Practice Drawings 132", 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
text = new Text(115, -halfHeight + 25, 0, "Date", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
text = new Text(115, -halfHeight + 15, 0, "Design", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
text = new Text(115, -halfHeight + 5, 0, "Check", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
text = new Text(180, -halfHeight + 25, 0, "Approve", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
line = new Line(halfWidth - 30, halfHeight - 15, halfWidth, halfHeight - 15);
design1.Entities.Add(line);
line = new Line(halfWidth - 30, halfHeight - 15, halfWidth - 30, halfHeight);
design1.Entities.Add(line);
text = new Text(halfWidth - 15, halfHeight - 7.5, 0, "132", 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
design1.Entities.Add(text);
design1.ActiveViewport.OriginSymbol.Visible = false;
design1.ActiveViewport.Grid.Visible = false;
design1.SetView(viewType.Top, true, false);
// shows print preview
Print();
base.OnLoad(e);
}
private void DrawTeeth()
{
const int teethNumber = 52;
Circle df = new Circle(0, 0, 0, 128);
RadialDim rDim = new RadialDim(df, new Point2D(180, -20), 8)
{
ArrowsLocation = elementPositionType.Outside,
TrimLeader = true
};
design1.Entities.Add(rDim, Dim);
design1.Entities.Add(new Arc(df.Center, 128, -0.15, -0.1), Dim);
Circle d = new Circle(0, 0, 0, 131.5);
rDim = new RadialDim(d, new Point2D(145, -100), 8)
{
ArrowsLocation = elementPositionType.Outside,
TrimLeader = true
};
design1.Entities.Add(rDim, Dim);
design1.Entities.Add(new Arc(d.Center, 131.5, -1, -0.6), Dim);
Circle MR = new Circle(0, 0, 0, 136);
rDim = new RadialDim(MR, new Point2D(-160, -70), 8)
{
ArrowsLocation = elementPositionType.Outside,
TrimLeader = true
};
design1.Entities.Add(rDim, Dim);
design1.Entities.Add(new Arc(MR.Center, 136, -2.75, -0.05), Dim);
// Tooth composed by line1, internalArc, line2, extArc
// calculation of extArc
double rad = devDept.Geometry.Utility.DegToRad(180 - 47.5);
Arc internalArc = new Arc(0, -131.5, 0, 5, devDept.Geometry.Utility.PI_2 - rad / 2, devDept.Geometry.Utility.PI_2 + rad / 2);
rDim = new RadialDim(internalArc, new Point2D(60, -40), 8)
{
ArrowsLocation = elementPositionType.Outside,
TrimLeader = true
};
design1.Entities.Add(rDim, Dim);
design1.Entities.Add(new Arc(internalArc.Center, 5, devDept.Geometry.Utility.DegToRad(-80), devDept.Geometry.Utility.DegToRad(-10)), Dim);
// calculatation of line 1 and 2
Line line1 = new Line(internalArc.StartPoint, internalArc.StartPoint + internalArc.StartTangent * -20);
Line line2 = new Line(internalArc.EndPoint, internalArc.EndPoint + internalArc.EndTangent * 20);
AngularDim angDim = new AngularDim(Plane.XY, line1, line2, new Point3D(0, -180, 0), new Point3D(0, -180, 0), 8);
angDim.TextSuffix = "°";
design1.Entities.Add(angDim, Dim);
line1.Reverse();
line1.TrimBy(MR.IntersectWith(line1)[0], true);
line2.TrimBy(MR.IntersectWith(line2)[0], false);
// calculation of extArc
var nextl1 = (Line)line1.Clone();
nextl1.Rotate(-devDept.Geometry.Utility.TWO_PI / teethNumber, Vector3D.AxisZ);
var seg = new Segment2D(line2.EndPoint, nextl1.StartPoint);
var radius = 8;
var h = Math.Sqrt((radius * radius) - ((seg.Length / 2) * (seg.Length / 2)));
var midPoint = seg.MidPoint;
Vector3D vector = Vector3D.Cross(new Vector3D(line2.EndPoint, nextl1.StartPoint), Vector3D.AxisZ); // vector perpendicular to the segment
vector.Length = h;
var center = midPoint + vector;
Arc extArc = new Arc(Plane.XY, center, nextl1.StartPoint, line2.EndPoint);
Arc copy = (Arc)extArc.Clone();
copy.Rotate(devDept.Geometry.Utility.TWO_PI / teethNumber * 6, Vector3D.AxisZ);
rDim = new RadialDim(copy, new Point2D(0.1, -10), 8)
{
ArrowsLocation = elementPositionType.Outside,
TrimLeader = true
};
design1.Entities.Add(rDim, Dim);
extArc.Reverse();
CompositeCurve cc = new CompositeCurve(internalArc, line1, line2, extArc);
CompositeCurve nextCC = (CompositeCurve)cc.Clone();
nextCC.Rotate((2 * Math.PI / teethNumber), Vector3D.AxisZ);
Arc arcdf = new Arc(new Point3D(0, 0, 0), cc.IntersectWith(df)[1], nextCC.IntersectWith(df)[0]);
for (int i = 0; i < teethNumber; i++)
{
CompositeCurve compCurve = (CompositeCurve)cc.Clone();
Arc arcdfi = (Arc)arcdf.Clone();
compCurve.Rotate((2 * Math.PI / teethNumber) * i, Vector3D.AxisZ);
arcdfi.Rotate((2 * Math.PI / teethNumber) * i, Vector3D.AxisZ);
design1.Entities.Add(compCurve);
design1.Entities.Add(arcdfi);
}
}
private void Print()
{
design1.PageSetup();
//Creates printing setting object and customize it
HiddenLinesViewSettingsEx hdlS = new HiddenLinesViewSettingsEx(viewType.Top, design1.Document);
hdlS.KeepEntityLineWeight = true;
//Creates paper preview
HiddenLinesViewOnPaperPreview hdl = new HiddenLinesViewOnPaperPreview(hdlS, new Size(800, 600), 0.5);
design1.StartWork(hdl);
}
Comments
Great article, very useful along with the DraftingDemo sample to get started with 2D drawing. Some features are a bit cumbersome, like linear dimensions. Is there any out-of-the-box function to draw fillings?
What do you mean by "draw fillings"? Hatch patterns?
Fills, not fillings, sorry. Yes, like hatch patterns.
Unfortunately, we don't support them natively, we only manage the import/export in DWG/DXF file formats
Grazie Simone
Is there anyway to change units?
For instance, if we specify dimensions in inch, but want to display in millimeters...
Please sign in to leave a comment.