// Define layer names and text size.
const string Dim = "Dimension", DashDot = "DashDot";
const double TextHeight = 2.0;
// Adding different layers
design1.Layers.Add(new Layer(Dim, Color.CornflowerBlue));
design1.Layers[0].LineWeight = 2;
design1.LineTypes.Add(DashDot, new float[] { 10, -2, 2, -2 });
// Y axis
Line axisY = new Line(0, -45, 0, 45)
{
LineTypeMethod = colorMethodType.byEntity,
LineTypeName = DashDot
};
design1.Entities.Add(axisY, Dim);
Transformation t = Transformation.CreateReflection(Plane.ZY);
// Building geometry - External Outline
Line lT1 = new Line(34.8, 30.2, 34.8, 44.6);
Line lT2 = new Line(28.8, 30.2, 28.8, 44.6);
Line lT3 = new Line(25.6, 32.6, 0.0, 32.6);
Circle c = new Circle(Plane.XY, new Point3D(31.8, 28, 0), 13.2);
Circle c_mir = (Circle)c.Clone();
c_mir.TransformBy(t);
Point3D int1 = c.IntersectWith(lT1)[0];
Point3D int2 = c.IntersectWith(lT2)[0];
Point3D int3 = c.IntersectWith(lT3)[0];
// External outline
Line eo1 = new Line(0.0, -36, 17.8, -36);
Line eo2 = new Line(17.8, -36, 17.8, -42);
Line eo3 = new Line(17.8, -42, 51, -42);
Line eo4 = new Line(51, -42, 51, -12.6);
Line eo5 = new Line(51, -12.6, 43.8, -12.6);
Line eo7 = new Line(43.8, 0.6, 51, 0.6);
Arc eo6 = new Arc(Plane.XY, new Point3D(43.8, -6.0, 0.0), 6.6, eo5.EndPoint, eo7.StartPoint, true);
Line eo8 = new Line(51, 0.6, 51, 22.6);
Line eo9 = new Line(51, 22.6, 45, 22.6);
Line eo10 = new Line(45, 22.6, 45, 28);
Arc eo11 = new Arc(Plane.XY, new Point3D(31.8, 28, 0), 13.2, eo10.EndPoint, int1, false);
Line eo12 = new Line(int1.X, int1.Y, 34.8, 44.6);
Line eo13 = new Line(34.8, 44.6, 28.8, 44.6);
Line eo14 = new Line(28.8, 44.6, int2.X, int2.Y);
Arc eo15 = new Arc(Plane.XY, new Point3D(31.8, 28, 0), 13.2, int2, int3, false);
Line eo16 = new Line(int3.X, int3.Y, 0, int3.Y);
Entity[] borders = new Entity[] { eo1, eo2, eo3, eo4, eo5, eo6, eo7, eo8, eo9, eo10, eo11, eo12, eo13, eo14, eo15, eo16 };
Entity[] mirroredBorders = new Entity[borders.Length];
for (int i = 0; i < borders.Length; i++)
{
mirroredBorders[i] = (Entity)borders[i].Clone();
mirroredBorders[i].TransformBy(t);
}
design1.Entities.AddRange(borders);
design1.Entities.AddRange(mirroredBorders);
// Holes
Circle c1 = new Circle(Plane.XY, new Point3D(31.8, 28, 0), 6);
Circle c2 = (Circle)c1.Clone();
c2.TransformBy(t);
CompositeCurve h1 = CompositeCurve.CreateHexagon(31.8, 28, 6);
h1.Rotate(Math.PI / 6, Vector3D.AxisZ, new Point3D(31.8, 28, 0));
h1.TransformBy(t);
// Building Geometry - Internal Holes
Circle bC1 = new Circle(Plane.XY, new Point3D(22.8, -6.0, 0.0), 6);
Circle bC2 = new Circle(Plane.XY, new Point3D(25.2, -6.0, 0.0), 6);
Circle bC3 = new Circle(Plane.XY, new Point3D(22.9, -15.57, 0.0), 3.7);
Point3D bPt = new Point3D(16.8, -14.5, 0.0);
Line[] tgts;
devDept.Geometry.Utility.GetLinesTangentToCircleFromPoint(bC1, bPt, out tgts);
Line lh1 = (Line)tgts[1].Clone();
Line lh2 = devDept.Geometry.Utility.GetLinesTangentToTwoCircles(bC1, bC2)[0];
Line lh3 = devDept.Geometry.Utility.GetLinesTangentToTwoCircles(bC2, bC3)[0];
devDept.Geometry.Utility.GetLinesTangentToCircleFromPoint(bC3, bPt, out tgts);
Line lh4 = tgts[0];
Arc lha1 = new Arc(Plane.XY, bC1.Center, bC1.Radius, lh2.StartPoint, lh1.EndPoint, false);
Arc lha2 = new Arc(Plane.XY, bC2.Center, bC1.Radius, lh2.EndPoint, lh3.StartPoint, true);
Arc lha3 = new Arc(Plane.XY, bC3.Center, bC3.Radius, lh3.EndPoint, lh4.EndPoint, true);
Entity[] holes = { c1, c2, h1, lh1, lh2, lh3, lh4, lha1, lha2, lha3 };
design1.Entities.AddRange(holes);
// Measures
Plane left = new Plane(Point3D.Origin, Vector3D.AxisY, -1 * Vector3D.AxisX); // plane.XY, vertical writing;
Dimension[] ld = new Dimension[]
{
// Radial
new RadialDim(eo6, new Point3D(58.0, 0.0, 0.0), TextHeight)
{
ArrowsLocation = elementPositionType.Inside,
CenterMarkSize = 9.0f,
LineTypeName = DashDot,
LineTypeMethod = colorMethodType.byEntity
},
new RadialDim(new Circle(((Arc)mirroredBorders[5]).Center, ((Arc)mirroredBorders[5]).Radius), new Point3D(-30.0, 5.0, 0.0), TextHeight)
{
ArrowsLocation = elementPositionType.Outside,
CenterMarkSize = 9.0f,
LineTypeName = DashDot,
LineTypeMethod = colorMethodType.byEntity
},
new RadialDim(new Circle(c_mir.Center, c_mir.Radius), new Point3D(-65.0, 40.0, 0.0), TextHeight)
{
ArrowsLocation = elementPositionType.Outside,
CenterMarkSize = 9.0f,
LineTypeName = DashDot,
LineTypeMethod = colorMethodType.byEntity,
TextPrefix = "2-R"
},
new RadialDim(bC1, new Point3D(15.0, 2.0, 0.0), TextHeight)
{
ArrowsLocation = elementPositionType.Outside
},
new RadialDim(bC2, new Point3D(30.0, 1.0, 0.0), TextHeight)
{
ArrowsLocation = elementPositionType.Outside
},
new RadialDim(bC3, new Point3D(30.0, -32.0, 0.0), TextHeight)
{
ArrowsLocation = elementPositionType.Outside
},
// Diametric
new DiametricDim(c1, new Point3D(20.0, 20.0, 0.0), TextHeight)
{
ArrowsLocation = elementPositionType.Outside,
TextPrefix = "2-Ø"
},
// Linear
new LinearDim(Plane.XY, new Point2D(-51.0, -42.0), new Point2D(51.0, -42.0), new Point2D(0.0, -70.0), TextHeight),
new LinearDim(Plane.XY, new Point2D(-17.8, -42.0), new Point2D(17.8, -42.0), new Point2D(0.0, -60.0), TextHeight),
new LinearDim(Plane.XY, new Point2D(-17.8, -42.0), new Point2D(-17.8, -42.0), new Point2D(0.0, -60.0), TextHeight),
new LinearDim(Plane.XY, new Point2D(-51.0, -42.0), new Point2D(-17.8, -42.0), new Point2D(-34.4, -60.0), TextHeight),
new LinearDim(left, new Point2D(-42.0, 51.0), new Point2D(44.6, 34.8), new Point2D(0.0, 80), TextHeight),
new LinearDim(left, new Point2D(-42.0, 51.0), new Point2D(-12.6, 51.0), new Point2D(-27.3, 60), TextHeight),
new LinearDim(left, new Point2D(-12.6, 51.0), new Point2D(0.6, 51.0), new Point2D(-6.0, 60), TextHeight),
new LinearDim(left, new Point2D(0.6, 51.0), new Point2D(22.8, 51.0), new Point2D(11.7, 60), TextHeight),
new LinearDim(Plane.XY, new Point2D(-51.0, 22.8), new Point3D(-31.8, 28, 0), new Point2D(-41.4, 70), TextHeight),
new LinearDim(Plane.XY, new Point3D(-31.8, 28, 0), new Point2D(31.8, 22.8), new Point2D(0.0, 70), TextHeight),
new LinearDim(left, new Point2D(-42, -51.0), new Point2D(-6, -51.0), new Point2D(-21, -70), TextHeight),
new LinearDim(left, new Point2D(-6, -51.0), new Point2D(28.2, -31.8), new Point2D(11.1, -70), TextHeight),
new LinearDim(Plane.XY, new Point2D(28.8, 44.6), new Point2D(34.8, 44.6), new Point2D(38.0, 49.6), TextHeight)
{
ArrowsLocation = elementPositionType.Outside
},
new LinearDim(Plane.XY, new Point2D(-28.8, 44.6), new Point2D(-34.8, 44.6), new Point2D(-38.0, 49.6), TextHeight)
{
ArrowsLocation = elementPositionType.Outside
},
new LinearDim(Plane.XY, new Point2D(-51.0, 22.8), new Point3D(-45.0, 30.0, 0), new Point2D(-48.0, 58.0), TextHeight),
new LinearDim(left, new Point2D(-42.0, 20.0), new Point2D(-36.0, 17.8), new Point2D(-39.0, 20.0), TextHeight),
new LinearDim(left, new Point2D(-36.0, 17.8), new Point2D(32.6, 19.0), new Point2D(-1.9, 20.0), TextHeight),
new LinearDim(left, new Point2D(-36.0, 12.0), new Point2D(0.0, 0.0), new Point2D(-18.0, 12.0), TextHeight),
new LinearDim(left, new Point2D(-36.0, 7.0), new Point2D(-14.5, -16.0), new Point2D(-25.25, 7.0), TextHeight)
{
ArrowsLocation = elementPositionType.Inside
},
new LinearDim(left, new Point2D(-36.0, -4.0), new Point2D(-15.57, -22.9), new Point2D(-25.79, -4.0), TextHeight)
{
ArrowsLocation = elementPositionType.Inside
},
new LinearDim(Plane.XY, new Point2D(43.8, -6.0), new Point2D(51.0, -20.0), new Point2D(54.0, -20.0), TextHeight)
{
ArrowsLocation = elementPositionType.Outside
},
new LinearDim(Plane.XY, new Point2D(-43.8, -6.0), new Point2D(-51.0, -20.0), new Point2D(-54.0, -20.0), TextHeight)
{
ArrowsLocation = elementPositionType.Outside
},
new LinearDim(Plane.XY, new Point2D(22.8, -6.0), new Point2D(25.2, -6.0), new Point2D(27.0, 10.0), TextHeight),
new LinearDim(Plane.XY, new Point2D(22.9, -15.57), new Point2D(16.8, -14.5), new Point2D(18.0, -30.0), TextHeight)
{
ArrowsLocation = elementPositionType.Outside
},
new LinearDim(Plane.XY, new Point2D(0.0, -9.5), new Point2D(16.8, -9.5), new Point2D(8.4, -9.5), TextHeight)
};
design1.Entities.AddRange(ld, Dim);
// Center figure into frame
design1.Entities.Translate(145, 100);
design1.Entities.Regen();
DrawFrame();
// Top View
design1.SetView(viewType.Top);
design1.ZoomFit();
Print();
Frame drawing:
void DrawFrame()
{
const double height = 200;
const double width = 287;
const string FrameLayer = "FrameLayer";
design1.Layers.Add(new Layer(FrameLayer));
design1.Layers[FrameLayer].LineWeight = 2;
// drawing the ln1
Line ln1 = new Line(0, 0, width, 0);
design1.Entities.Add(ln1, FrameLayer);
ln1 = new Line(width, 0, width, height);
design1.Entities.Add(ln1, FrameLayer);
ln1 = new Line(width, height, 0, height);
design1.Entities.Add(ln1, FrameLayer);
ln1 = new Line(0, height, 0, 0);
design1.Entities.Add(ln1, FrameLayer);
}
Printing on A4 paper sheet:
private async 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);
await design1.DoWorkAsync(hdl);
}
Comments
Hi,
if I create a DXF file of the model I am getting "Realistic" visual style instead of "2D Wireframe" when I open it with Autocad.
How can I force "2D Wireframe"? Setting design1.DisplayMode to displayType.Wireframe gives "Wireframe" which is optimized for 3D.
Thanks,
Stenio
Please sign in to leave a comment.