CAD Practice Drawings 116

CAD-drawing-116.png

Define layer names and text size.

private const string 
            DimLayer = "Dimension",
            ThinLayer = "ThinLayer",
            DashDot = "DashDot";

private const double TextHeight = 3.5;

Draw the component and its dimensions.

// Set layers and linetype
design1.Layers[0].LineWeight = 2;
design1.Layers.Add(new Layer(DimLayer, Color.CornflowerBlue));
design1.Layers.Add(new Layer(ThinLayer));
design1.LineTypes.Add(DashDot, new float[] {
    30,
    -5,
    5,
    -5
});

// Main circles
Circle circleTopCenterInner = new Circle(0, 0, 0, 14);
Circle circleTopCenterOuter = new Circle(0, 0, 0, 19);
Circle circleTopLeft = new Circle(-41, 0, 0, 10);
Circle circleBottomCenter = new Circle(0, -90, 0, 10);

// Outline circles
Circle c1 = new Circle(Plane.XY, new Point2D(0, 0), 40); // Outer circle top right
Circle c2 = new Circle(Plane.XY, new Point2D(0, -90), 20); // Outer circle bottom
Circle c3 = new Circle(Plane.XY, new Point2D(-41, 0), 20); // Outer circle top left 

// Linking arcs
Arc a98 = (Arc) UtilityEx.GetCirclesTangentToTwoCircles(c1, c2, 98, true)[3]; // Radius 98 arc
Arc a20 = (Arc) UtilityEx.GetCirclesTangentToTwoCircles(c1, c2, 20, true)[1]; // Radius 20 arc
Arc a9 = (Arc) UtilityEx.GetCirclesTangentToTwoCircles(c3, c1, 9, true)[0]; // Radius 9 arc

Arc a1 = new Arc(c1.Center, c1.Radius, Math.PI * 2);
a1.TrimBy(a9.EndPoint, false);
a1.TrimBy(a98.StartPoint, true);

Arc a2 = new Arc(c2.Center, c2.Radius, Math.PI * 2);
a2.TrimBy(a98.EndPoint, false);
a2.TrimBy(a20.EndPoint, true);

Arc a3 = new Arc(c3.Center, c3.Radius, Math.PI * 3 / 2);
a3.TrimBy(a9.StartPoint, true);

Line l = new Line(a3.EndPoint, new Point3D(0, a3.EndPoint.Y, 0));
l.TrimBy(c1.IntersectWith(l)[0], false);

Arc c1Arc2 = new Arc(c1.Center, c1.Radius, Math.PI * 2);
c1Arc2.TrimBy(l.EndPoint, true);
c1Arc2.TrimBy(a20.StartPoint, false);

// Add shapes
design1.Entities.AddRange(new Entity[] {
    circleTopCenterInner,
    circleTopCenterOuter,
    circleTopLeft,
    circleBottomCenter,
    a98,
    a20,
    a9,
    a1,
    a2,
    a3,
    l,
    c1Arc2,
    UtilityEx.GetLinesTangentToTwoCircles(c2, c3)[0]
});

// Add dimensions
Plane left = new Plane(Point3D.Origin, Vector3D.AxisY, -1 * Vector3D.AxisX);

a98.Reverse(); // Fix normals to display text correctly
a20.Reverse();

design1.Entities.AddRange(new Entity[] {

    // Diametric dimensions
    new DiametricDim(circleTopCenterInner, new Point2D(20, 20), TextHeight),
        new DiametricDim(circleTopCenterOuter, new Point2D(20, -20), TextHeight),
        new DiametricDim(circleTopLeft, new Point2D(-22, -22), TextHeight),
        new DiametricDim(circleBottomCenter, new Point2D(20, -20), TextHeight),

        // Linear dimensions
        new LinearDim(Plane.XY, new Point2D(-41, -150), new Point2D(0, -150), new Point2D(-20, -150), TextHeight),
        new LinearDim(left, new Point2D(-90, -80), new Point2D(0, -80), new Point2D(-45, -80), TextHeight),

        // Radial dimensions
        new RadialDim(c2, new Point2D(-20, -30), TextHeight) {
            ArrowsLocation = elementPositionType.Outside,
                TrimLeader = true
        },
        new RadialDim(c3, new Point2D(-20, 20), TextHeight) {
            ArrowsLocation = elementPositionType.Outside,
                TrimLeader = true
        },
        new RadialDim(a9, new Point2D(15, 15), TextHeight) {
            ArrowsLocation = elementPositionType.Outside,
                TrimLeader = true,
                CenterMarkSize = 0 d
        },
        new RadialDim(c1, new Point2D(50, 30), TextHeight) {
            ArrowsLocation = elementPositionType.Outside
        },
        new RadialDim(c1, new Point2D(-30, -50), TextHeight) {
            ArrowsLocation = elementPositionType.Outside
        },
        new RadialDim(a98, new Point2D(82, -82), TextHeight) {
            ArrowsLocation = elementPositionType.Outside,
                TrimLeader = true,
                CenterMarkSize = 0 d
        },
        new RadialDim(a20, new Point2D(20, -40), TextHeight) {
            ArrowsLocation = elementPositionType.Outside,
                TrimLeader = true,
                CenterMarkSize = 0 d
        },

        // Axes
        new Line(-70, 0, 80, 0) { // Top X axis
            LineTypeMethod = colorMethodType.byEntity,
                LineTypeName = DashDot
        },
        new Line(-30, -90, 80, -90) { // Bottom X axis
            LineTypeMethod = colorMethodType.byEntity,
                LineTypeName = DashDot
        },
        new Line(-41, 30, -41, -150) { // Left Y axis
            LineTypeMethod = colorMethodType.byEntity,
                LineTypeName = DashDot
        },
        new Line(0, 50, 0, -150) { // Right Y axis
            LineTypeMethod = colorMethodType.byEntity,
                LineTypeName = DashDot
        }

}, DimLayer);

// Scale and translate component
double scale = 2;

design1.Entities.Scale(scale);

foreach(Entity en in design1.Entities)
if (en is Dimension)
    // Restore original measure
    ((Dimension) en).LinearScale = 1 / scale;

design1.Entities.Translate(-12, 100);
design1.Entities.Regen();

// Draw frame
DrawFrame();

// Viewport setup
design1.SetView(viewType.Top, true, false);
design1.ActiveViewport.Grid.Visible = false; // Hide grid
design1.ActiveViewport.OriginSymbol.Visible = false; // Hide origin

// Print
Print();

Utility function to draw the outline frame.

void DrawFrame() {
    string frameID = "116";
    string frameTitle = "CAD Practice Drawing " + frameID;
    int halfWidth = 200;
    int halfHeight = 287;

    design1.Entities.AddRange(new Entity[] {

        new LinearPath(-halfWidth, -halfHeight, 2 * halfWidth, 2 * halfHeight),

            new Line(-halfWidth / 4, -halfHeight + 30, halfWidth, -halfHeight + 30),
            new Line(-halfWidth / 4, -halfHeight + 30, -halfWidth / 4, -halfHeight),

            new Text(25, -halfHeight + 25, 0, "Title", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
            new Text(25, -halfHeight + 10, 0, frameTitle, 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
            new Text(115, -halfHeight + 25, 0, "Date", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
            new Text(115, -halfHeight + 15, 0, "Design", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
            new Text(115, -halfHeight + 5, 0, "Check", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),
            new Text(180, -halfHeight + 25, 0, "Approve", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter),

            new Line(halfWidth - 30, halfHeight - 15, halfWidth, halfHeight - 15),
            new Line(halfWidth - 30, halfHeight - 15, halfWidth - 30, halfHeight),
            new Text(halfWidth - 15, halfHeight - 7.5, 0, frameID, 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter)

    });

    // Add thin lines
    design1.Entities.AddRange(new Entity[] {

        new Line(-halfWidth / 4, -halfHeight + 20, halfWidth, -halfHeight + 20),
            new Line(100, -halfHeight + 30, 100, -halfHeight),
            new Line(130, -halfHeight + 30, 130, -halfHeight),
            new Line(160, -halfHeight + 30, 160, -halfHeight),
            new Line(100, -halfHeight + 10, 160, -halfHeight + 10)

    }, ThinLayer);
}

Utility function to adjust and print the viewport.

private void Print() {
    design1.PageSetup();

    //Save current view Camera
    design1.SaveView(out Camera cameraSaved);

    design1.ActiveViewport.Camera.ProjectionMode = projectionType.Orthographic;

    //Creates printing setting object and customize it
    HiddenLinesViewSettingsEx hdlS = new HiddenLinesViewSettingsEx(design1.ActiveViewport.Camera, design1.Document, hiddenLinesViewType.Extents) {
        KeepEntityLineWeight = true
    };

    //Creates paper preview
    HiddenLinesViewOnPaperPreview hdl = new HiddenLinesViewOnPaperPreview(hdlS, new Size(800, 600), 0.5);
    design1.StartWork(hdl);

    //Restore saved view
    design1.RestoreView(cameraSaved);
}

Don't forget to add the following using statements:

using devDept.Eyeshot.Entities;
using devDept.Eyeshot;
using devDept.Geometry;
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