🌶️ CAD Drawing Practice

Draw the figure

design1.Layers[0].LineWeight = 2;
design1.Grid.Visible = false;
design1.OriginSymbol.Visible = false;  
const string DashDot = "DashDot";
design1.LineTypes.Add(DashDot, new float[] { 5, -1, 1, -1 });
const double TextHeight = 4;
  
//Plane
Plane plane1 = Plane.XY;
plane1.Rotate(Math.PI/2, Vector3D.AxisZ);
Plane plane2 = Plane.XY;
plane2.Rotate(-Math.PI, Vector3D.AxisZ);

//Internal contour
Circle c1 = new Circle(0, 0, 0, 21);
Circle c2 = new Circle(0, 50, 0, 9);
Circle c3 = new Circle(50, 50, 0, 6);
Circle c4 = new Circle(90, 50, 0, 6);
Arc is1 = (Arc)UtilityEx.GetCirclesTangentToTwoCircles(c2, c1, 30, true)[1];
Arc is2 = (Arc)UtilityEx.GetCirclesTangentToTwoCircles(c1, c2, 30, true)[1];
Arc is3 = new Arc(plane1, c1.Center, c1.Radius, Math.PI * 2);
is3.TrimBy(is2.StartPoint, false);
is3.TrimBy(is1.EndPoint, true);
plane1.Rotate(Math.PI, Vector3D.AxisZ);
Arc is4 = new Arc(plane1, c2.Center, c2.Radius, Math.PI * 2);
is4.TrimBy(is2.EndPoint, true);
is4.TrimBy(is1.StartPoint, false);
Line is5 = Utility.GetLinesTangentToTwoCircles(c4, c3)[1];
Line is6 = Utility.GetLinesTangentToTwoCircles(c3, c4)[1];
Arc is7 = new Arc(c3.Center, c3.Radius, Math.PI * 2);
is7.TrimBy(is6.StartPoint, false);
is7.TrimBy(is5.EndPoint, true);
plane1.Rotate(4 * 0.85, Vector3D.AxisZ);
Arc is8 = new Arc(plane1, c4.Center, c4.Radius, Math.PI * 2);
is8.TrimBy(is6.EndPoint, true);
is8.TrimBy(is5.StartPoint, false);

//External contour
Circle c5 = new Circle(0, 0, 0, 30);
Circle c6 = new Circle(90, 50, 0, 15);
Circle c7 = new Circle(0, 50, 0, 15);
Arc  es1= (Arc)UtilityEx.GetCirclesTangentToTwoCircles(c5, c6, 50, true)[1];
Line es2 = Utility.GetLinesTangentToTwoCircles(c7, c5)[1];
Line es3 = Utility.GetLinesTangentToTwoCircles(c6, c7)[1];
Arc es4 = new Arc(c5.Center, c5.Radius, Math.PI * 2);
es4.TrimBy(es2.EndPoint, true);
es4.TrimBy(es1.StartPoint, false);
Arc es5 = new Arc(c7.Center, c7.Radius, Math.PI * 2);
es5.TrimBy(es2.StartPoint, false);
es5.TrimBy(es3.EndPoint, true);
Arc es6 = new Arc(plane2, c6.Center, c6.Radius, Math.PI * 2);
es6.TrimBy(es3.StartPoint, false);
es6.TrimBy(es1.EndPoint, true);

//Add all contours
design1.Entities.AddRange(new Entity[] { is3, is1, is2, is4, is7, is8, is5, is6, es1, es2, es3, es4, es5, es6 });

Draw the dimensions

const string DimLayer = "Dimension";
design1.Layers.Add(new Layer(DimLayer, Color.CornflowerBlue));

//Dimensions
Plane vertical = new Plane(Point3D.Origin, Vector3D.AxisY, Vector3D.AxisMinusX);
Plane htwvertical = Plane.XY;
htwvertical.Rotate(-Math.PI, Vector3D.AxisZ);

LinearDim ld1 = new LinearDim(vertical, new Point3D(-57, 0, 0), new Point3D(-57, 50, 0), new Point3D(-57, 25, 0), TextHeight);
LinearDim ld2 = new LinearDim(Plane.XY, new Point3D(0, -45, 0), new Point3D(90, -45, 0), new Point3D(45, -45, 0), TextHeight);
LinearDim ld3 = new LinearDim(Plane.XY, new Point3D(0, 84, 0), new Point3D(50, 84, 0), new Point3D(25, 84, 0), TextHeight);
LinearDim ld4 = new LinearDim(Plane.XY, new Point3D(50, 84, 0), new Point3D(90, 84, 0), new Point3D(70, 84, 0), TextHeight);
RadialDim R21 = new RadialDim(c1, 2 * c1.PointAt(Math.PI * 5 / 4), TextHeight) { ArrowsLocation = elementPositionType.Outside };
RadialDim R30 = new RadialDim(c5, 2 * c1.PointAt(Math.PI * 9 / 8), TextHeight) { ArrowsLocation = elementPositionType.Outside };
RadialDim R9 = new RadialDim(c2, 1.1 * c2.PointAt(0.0001), TextHeight) { ArrowsLocation = elementPositionType.Outside };
RadialDim R6 = new RadialDim(c3, new Point3D(40, 46, 0), TextHeight) { ArrowsLocation = elementPositionType.Outside };
RadialDim R15 = new RadialDim(c6, c6.PointAt(Math.PI / 4), TextHeight) { ArrowsLocation = elementPositionType.Outside };
RadialDim R30_1 = CreateRadialDim(is2, 3.5, 30, TextHeight);
RadialDim R30_2 = CreateRadialDim(is1, -0.3, 30, TextHeight);
RadialDim R50 = CreateRadialDim(es1, Math.PI * 3 / 4, 50, TextHeight);
RadialDim R15_1 = new RadialDim(c7, 1.001 * es5.MidPoint, TextHeight);
Line L1 = new Line(0, -45.5, 0, -26);
Line L2 = new Line(-57.1, 0, -26, 0);
Line L3 = new Line(0, 85.5, 0, 62);
Line L4 = new Line(50, 85.5, 50, 60);
Line L5 = new Line(90, 85.5, 90, 60);
Line L6 = new Line(90, -45.5, 90, 39);
Line L7 = new Line(-57.1, 50, -13.5, 50);

//Add dimensions
design1.Entities.AddRange(new Entity[] { ld1, ld2, ld3, ld4, R21, R30, R9, R6, R15, R30_1, R30_2, R50, R15_1, L1, L2, L3, L4, L5, L6, L7 }, DimLayer);

Draw the construction lines

const string Construction = "Construction";
design1.Layers.Add(new Layer(Construction, Color.DarkViolet, DashDot));
//Dashdot 
Line cl1 = new Line(0, 25, 0, -25);
Line cl2 = new Line(25, 0, -25, 0);
Line cl3 = new Line(10, 50, -10, 50);
Line cl4 = new Line(0, 60, 0, 40);
Line cl5 = new Line(50, 57, 50, 43);
Line cl6 = new Line(57.8, 50, 41.8, 50);
Line cl7 = new Line(97, 50, 83, 50);
Line cl8 = new Line(90, 57, 90, 43);

//Add construction lines
design1.Entities.AddRange(new Entity[] { cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8 }, Construction);

Viewport setup

design1.Entities.Translate(120, 100);
DrawFrame();
design1.Entities.Regen();
design1.SetView(devDept.Eyeshot.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 function 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);
 }

 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);
 }

 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);
 }

 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);
 }

 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);
 }

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