CAD Practice Drawings 2D-01

Define layers, linetypes and text height.

design1.Layers[0].LineWeight = 2;
const string DashDot = "DashDot";
design1.LineTypes.Add(DashDot, new float[] { 5, -1, 1, -1 });
const string DimLayer = "Dimension"; design1.Layers.Add(new Layer(DimLayer, Color.CornflowerBlue)); const string Construction = "Construction"; design1.Layers.Add(new Layer(Construction, Color.DarkViolet, DashDot));
const double TextHeight = 2;

Draw the components.

Circle c1 = new Circle(0, 0, 0, 14.5);
Circle c2 = new Circle(0, 0, 0, 23);
Circle c3 = new Circle(-38, 5, 0, 9);
Circle c4 = new Circle(-38, 5, 0, 5.5);
Line l1 = UtilityEx.GetLinesTangentToTwoCircles(c2, c3)[1];
Line l2 = new Line(-47, 5, -47, -22);
Arc a1 = new Arc(-37, -22, 0, 10, 0, Math.PI * 2);
Line l3 = new Line(-22.6, -47, -22.6, -67);
Arc a3 = new Arc(-32.6, -47, 0, 10, 0, Math.PI * 2);
Circle a2 = UtilityEx.GetCirclesTangentToTwoCircles(a1, a3, 30, true)[6];
a1.TrimBy(l2.EndPoint, true);
a1.TrimBy(a2.StartPoint, false);
a3.TrimBy(a2.EndPoint, false);
a3.TrimBy(l3.StartPoint, true);
Line l4 = new Line(-22.6, -67, 13.4, -67);

Plane htw = Plane.XY;
htw.Rotate(Math.PI / 3, Vector3D.AxisZ);
htw.Translate(l4.EndPoint.AsVector);
Line l5 = new Line(htw, 0, 0, 9.5, 0);
Line l6 = new Line(htw, 9.5, 0, 9.5, 10);
Arc a4 = new Arc(htw, new Point2D(12.5, 10), 3, 0, Math.PI);
Line l7 = new Line(htw, 15.5, 10, 15.5, 0);
Line l8 = new Line(htw, 15.5, 0, 18.5, 0);
Line l9 = new Line(htw, 18.5, 0, 18.5, 10);
Arc a5 = new Arc(htw, new Point2D(21.5, 10), 3, 0, Math.PI);
Line l10 = new Line(htw, 24.5, 10, 24.5, 0);
Line l11 = new Line(htw, 24.5, 0, 27.5, 0);
Line l12 = new Line(htw, 27.5, 0, 27.5, 10);
Arc a6 = new Arc(htw, new Point2D(30.5, 10), 3, 0, Math.PI);
Line l13 = new Line(htw,33.5, 10, 33.5, 0);
Line l14 = new Line(htw, 33.5, 0, 42, 0);
Line l15 = new Line(htw, 42, 0, 42, 24);
Circle c5 = new Circle(-9, -47, 0, 3);
Circle c6 = new Circle(-9, -47, 0, 5);
Line l16 = UtilityEx.GetLinesTangentToTwoCircles(c2, c6)[1];
Line l17 = UtilityEx.GetLinesTangentToCircleFromPoint(c6, new Point3D(-4, -30))[1];

Plane newpl = Plane.XY;
newpl.Rotate(Utility.DegToRad(36.5), Vector3D.AxisZ);
newpl.Translate(l15.EndPoint.AsVector);
Line l18 = new Line(newpl, 0, 0, -22, 0);

l17.TrimBy(Utility.Intersection(l17, l18)[0], true);

design1.Entities.AddRange(new Entity[] { c1, c2, c3, c4, c5, c6, a1, a2, a3, a4, a5, a6, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, l17, l18});

Draw the dimensions.

Plane vertical = new Plane(Point3D.Origin, Vector3D.AxisY, Vector3D.AxisMinusX);
Plane htwvertical = Plane.XY;
htwvertical.Rotate(-Math.PI / 6, Vector3D.AxisZ);
htwvertical.Translate(l5.StartPoint.AsVector);
LinearDim ld1 = new LinearDim(vertical, new Point3D(-57, 5, 0), new Point3D(-57, 0, 0), new Point3D(-57, 2.5, 0), TextHeight);
LinearDim ld2 = new LinearDim(vertical, new Point3D(-57, 0, 0), (Point3D)l2.EndPoint.Clone(), new Point3D(-57, -11, 0), TextHeight);
LinearDim ld3 = new LinearDim(vertical, (Point3D)l2.EndPoint.Clone(), new Point3D(-57, -47, 0), new Point3D(-57, -34.5, 0), TextHeight);
LinearDim ld4 = new LinearDim(vertical, new Point3D(-57, -47, 0), l3.EndPoint, new Point3D(-57, -57, 0), TextHeight);
LinearDim ld5 = new LinearDim(Plane.XY, new Point3D(0, 28, 0), new Point3D(-38, 28, 0), new Point3D(-19, 28, 0), TextHeight);
LinearDim ld6 = new LinearDim(Plane.XY, (Point3D)l4.StartPoint.Clone(), new Point3D(-9, -77, 0), new Point3D(-15.8, -77, 0), TextHeight);
LinearDim ld7 = new LinearDim(Plane.XY, new Point3D(-9, -77, 0), new Point3D(0, -77, 0), new Point3D(-4.5, -77, 0), TextHeight);
LinearDim ld8 = new LinearDim(Plane.XY, (Point3D)l4.StartPoint.Clone(), (Point3D)l4.EndPoint.Clone(), new Point3D(-4.6, -87, 0), TextHeight);
LinearDim ld9 = new LinearDim(htw, new Point2D(0, 0), new Point2D(42, 0), new Point2D(21, -20), TextHeight);
LinearDim ld10 = new LinearDim(htw, new Point2D(24.5, 0), new Point2D(27.5, 0), new Point2D(26, -10), TextHeight);
LinearDim ld11 = new LinearDim(htw, new Point2D(33.5, 0), new Point2D(42, 0), new Point2D(37.75, -10), TextHeight);
LinearDim ld12 = new LinearDim(htwvertical, new Point2D(0, 27.5), new Point2D(-10, 27.5), new Point2D(-5, 30), TextHeight);
LinearDim ld13 = new LinearDim(htwvertical, new Point2D(0, 42), new Point2D(-24, 42), new Point2D(-12, 47), TextHeight);
LinearDim ld14 = new LinearDim(newpl, new Point2D(0, 0), new Point2D(-22, 0), new Point2D(-11, -5), TextHeight);
RadialDim rd1 = new RadialDim(c3, new Point3D(-52, 19, 0), TextHeight);
RadialDim rd2 = new RadialDim(c4, new Point3D(-26, 12, 0), TextHeight);
RadialDim rd3 = new RadialDim(a1, a1.MidPoint, TextHeight);
RadialDim rd4 = CreateRadialDim(a2, 4*Math.PI / 3, 35, TextHeight);
RadialDim rd5 = new RadialDim(a3, a3.MidPoint, TextHeight);
RadialDim rd6 = new RadialDim(c1, 2*c1.PointAt(Math.PI / 4), TextHeight);
RadialDim rd7 = new RadialDim(c2, c2.PointAt(Math.PI / 6), TextHeight);
RadialDim rd8 = new RadialDim(c5, new Point3D(4,-40,0), TextHeight);
RadialDim rd9 = new RadialDim(c6, new Point3D(4,-50,0), TextHeight);
RadialDim rd10 = new RadialDim(a6, new Point3D(10, -36, 0), TextHeight);
AngularDim ad1 = new AngularDim(Plane.XY, (Point3D)l4.EndPoint.Clone(), htw.PointAt(5,0), new Point2D(8.4, -67), new Point2D(13.4 - 2.5, -67+ 2.5 * Math.Sqrt(3)), TextHeight);
AngularDim ad2 = new AngularDim(Plane.XY, (Point3D)l17.StartPoint.Clone(), newpl.PointAt(-12, 0), (Point3D)l17.StartPoint.Clone()-((Line)l17.Clone()).StartTangent.AsPoint, new Point2D(4, -20), TextHeight);

design1.Entities.AddRange(new Entity[] { ld1, ld2, ld3, ld4, ld5, ld6, ld7, ld8, ld9, ld10, ld11, ld12, ld13, ld14, rd1, rd2, rd3, rd4, rd5, rd6, rd7, rd8, rd9, rd10, ad1, ad2}, DimLayer);

Line cl1 = new Line(0, -77, 0, 28);
Line cl2 = new Line(-57, 0, 25, 0);
Line cl3 = new Line(new Point3D(-57, 5, 0), new Point3D(-25, 5, 0));
Line cl4 = new Line(new Point3D(-38, -8, 0), new Point3D(-38, 28, 0));
Line cl5 = new Line(new Point3D(-2, -47, 0), new Point3D(-57, -47, 0));
Line cl6 = new Line(new Point3D(-9, -40, 0), new Point3D(-9, -77, 0));

design1.Entities.AddRange(new Entity[] { cl1, cl2, cl3, cl4, cl5, cl6 }, Construction);

Viewport setup.

design1.Entities.Translate(150, 150);
design1.Entities.Regen(); DrawFrame();
design1.SetView(viewType.Top); design1.ZoomFit();

Utility function used to create a radial dimension.

private RadialDim CreateRadialDim(Circle a, double rotation, double distanceFromCenter, double textH)
{
    //Returns a radial dimension on the XY plane oriented according to rotation and distanceFromCenter.
    //The rotation follows the trigonometric standard for angles.

    Circle cr = new Circle(Plane.XY, a.Center, a.Radius);
    Point3D dlp = new Point3D(distanceFromCenter, 0, 0);
    dlp.TransformBy(new Rotation(rotation, Vector3D.AxisZ));
    dlp.TransformBy(new Translation(a.Center.X, a.Center.Y));
    return new RadialDim(cr, dlp, textH);
}

Utility functions used to print the frame.

void DrawFrame()
{
    const string frameLayerName = "Frame", frameTextLayerName = "FrameText";

    design1.Layers.Add(new Layer(frameLayerName) { LineWeight = 2 });
    design1.Layers.Add(new Layer(frameTextLayerName));

    double height = 210, width = 287; // A4 landscape
                                      // double height = 287, width = 210; // 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("CAD Practice Drawing 2D-01", 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);
}

image.png

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.

Articles in this section

See more