Drawing 2D-01

const string dimLayerName = "Dimension", 
  linetypeName = "DashDot", 
  referenceLayerName = "Reference";

Plane vertical = new Plane(Point3D.Origin, Vector3D.AxisY, -1 * Vector3D.AxisX); // plane.XY;

// adding different layers
design1.LineTypes.Add(linetypeName, new float[] { 10, -2, 2, -2 });

design1.Layers[0].LineWeight = 2;
design1.Layers.Add(new Layer(dimLayerName, Color.CornflowerBlue)
{
    LineWeight = 0.5f 
});
design1.Layers.Add(new Layer(referenceLayerName, Color.CornflowerBlue, linetypeName, 0.5f, true));


// Outer shape
Arc a = new Arc(Plane.XY, new Point3D(15, 15), 100, Utility.DegToRad(-20), Utility.DegToRad(120));

Line leftEdge = new Line(Plane.XY, new Point2D(0, 15), new Point2D(0, 130)); // left longer line
Utility.IntersectionLineCircle(leftEdge, a, Plane.XY, out Point3D i0, out _);
a.TrimBy(i0,false);
leftEdge.TrimBy(i0, false);

Line lowerEdge = new Line(Plane.XY, new Point2D(15, 0), new Point2D(130, 0)); // lower longer line
Utility.IntersectionLineCircle(lowerEdge, a, Plane.XY, out Point3D i1, out _);
a.TrimBy(i1, true);
lowerEdge.TrimBy(i1, false);

CompositeCurve outerFigure = new CompositeCurve(
    new Line(Plane.XY, new Point2D(0, 15), new Point2D(15, 15)), // inner dent upper edge
    new Line(Plane.XY, new Point2D(15, 15), new Point2D(15, 0)),  // inner dent right edge
    lowerEdge, a, leftEdge
);

design1.Entities.Add(outerFigure);

// Inner circles and lines

const int count = 5;

for (int i = 0; i <= count; i++)
{
    Circle smallerCircle = new Circle(new Point3D(60, 15), 5);
    smallerCircle.Rotate(Utility.DegToRad(90.0 / count * i),Vector3D.AxisZ, new Point3D(15,15));
    design1.Entities.Add(smallerCircle);

    Circle largerCircle = new Circle(new Point3D(95, 15), 8);
    largerCircle.Rotate(Utility.DegToRad(90.0 / count * i), Vector3D.AxisZ, new Point3D(15, 15));
    design1.Entities.Add(largerCircle);

    Line dotLine = new Line(Plane.XY, new Point2D(15, 15), new Point2D(120, 15))
    {
        LineTypeMethod = colorMethodType.byEntity,
        LineTypeName = linetypeName
    };
    dotLine.Rotate(Utility.DegToRad(90.0 / count * i), Vector3D.AxisZ, new Point3D(15, 15));

    design1.Entities.Add(dotLine, dimLayerName);
}

Arc smallerArc = new Arc(Plane.XY, new Point3D(15, 15), 45, Utility.DegToRad(-25), Utility.DegToRad(115));
design1.Entities.Add(smallerArc, referenceLayerName);

Arc largerArc = new Arc(Plane.XY, new Point3D(15, 15), 80, Utility.DegToRad(-15), Utility.DegToRad(105));
design1.Entities.Add(largerArc, referenceLayerName);


// Dimensions
Circle ref1 = (Circle) design1.Entities[16];
Circle temp1 = new Circle(Plane.XY, ref1.Center, ref1.Radius);
const double textHeight = 3;

DiametricDim dimSmallerCircle = new DiametricDim(temp1, new Point2D(-22, 7), textHeight);
design1.Entities.Add(dimSmallerCircle, dimLayerName);

Circle ref2 = (Circle)design1.Entities[14];
Circle temp2 = new Circle(Plane.XY, ref2.Center, ref2.Radius);
DiametricDim dimLargerCircle = new DiametricDim(temp2, new Point2D(30, 18), textHeight);
design1.Entities.Add(dimLargerCircle, dimLayerName);

RadialDim arcRadialDim = new RadialDim(a, new Point2D(100, 45), textHeight)
{
    ArrowsLocation = elementPositionType.Outside,
    TrimLeader = true,
    CenterMarkSize = 0
};
design1.Entities.Add(arcRadialDim, dimLayerName);

RadialDim smallerArcRadialDim = new RadialDim((Arc)design1.Entities[19], new Point2D(50, -22), textHeight)
{
    ArrowsLocation = elementPositionType.Outside,
    TrimLeader = true,
    CenterMarkSize = 0
};
design1.Entities.Add(smallerArcRadialDim, dimLayerName);

RadialDim largerArcRadialDim = new RadialDim((Arc)design1.Entities[20], new Point2D(88, -22), textHeight)
{
    ArrowsLocation = elementPositionType.Outside,
    TrimLeader = true,
    CenterMarkSize = 0
};
design1.Entities.Add(largerArcRadialDim, dimLayerName);

Point3D lowerRight = (Point3D) outerFigure.CurveList[0].StartPoint.Clone();
Point3D upperLeft  = (Point3D) outerFigure.CurveList[1].EndPoint.Clone();

LinearDim upperDentDim = new LinearDim(Plane.XY, lowerRight, upperLeft, new Point3D(7.5, -15), textHeight);

design1.Entities.Add(upperDentDim, dimLayerName);

LinearDim rightDentDim = new LinearDim(vertical, lowerRight, upperLeft, new Point3D(-15, 7.5), textHeight);

design1.Entities.Add(rightDentDim, dimLayerName);

// relocation
design1.Entities.Translate(100,60);
design1.Entities.Regen();
      
DrawFrame();

design1.SetView(viewType.Top, true, false);

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

private void Print()
{
    // A4 size in hundredth of inches
    PaperSize paperSize = new System.Drawing.Printing.PaperSize("A4", 826, 1169); 
    design1.PageSetup(true, false, 0, paperSize, true);

    // 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);
    design1.StartWork(hdl);
}

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

Comments

0 comments

Please sign in to leave a comment.

Articles in this section

See more