Define layer names and text size.
private const string
DimLayer = "Dimension",
ThinLayer = "ThinLayer",
DashDot = "DashDot";
private const double TextHeight = 2.5;
Draw the component and its dimensions.
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[] {10, -2 , 2, -2});
design1.SetView(viewType.Top);
//Center hexagon
CompositeCurve hexagon = CompositeCurve.CreateHexagon(0, 0,10,Math.PI/2, true);
//Circle inside hexagon
Circle cr1 = new Circle(0, 0, 0, 10);
cr1.LineTypeName = DashDot;
cr1.LineTypeMethod = colorMethodType.byEntity;
//Center DashDot line of the image
Line l1 = new Line(-80, 0, 80, 0);
l1.LineTypeName = DashDot;
l1.LineTypeMethod = colorMethodType.byEntity;
//DashDot circle with diameter 25
Circle cr2 = new Circle(-50, -12.5, 0, 12.5);
cr2.LineTypeName = DashDot;
cr2.LineTypeMethod = colorMethodType.byEntity;
//X axis DashDot circle witch diameter 25
Line l2 = new Line(-65, -12.5, -35, -12.5);
l2.LineTypeName = DashDot;
l2.LineTypeMethod = colorMethodType.byEntity;
//Upper line of the figure
Line upperLine = new Line(-100, 15, 40, 15);
upperLine.Rotate(Utility.DegToRad(30), Vector3D.AxisZ);
upperLine.TrimBy(l1.IntersectWith(upperLine)[0], true);
//Lower line of the figure
Line lowerLine = new Line(-100, -15, 40, -15);
lowerLine.Rotate(Utility.DegToRad(30), Vector3D.AxisZ);
lowerLine.TrimBy(l1.IntersectWith(lowerLine)[0], false);
//Starting point for the upper line of the figure
Point3D[] startUpperLine = l1.IntersectWith(upperLine);
//Left tangent line to the circle with diameter 25
Line[] tgl;
Utility.GetLinesTangentToCircleFromPoint(cr2, startUpperLine[0], out tgl);
Line tangentLeft = tgl[1];
Point3D[] intPoint1 = tangentLeft.IntersectWith(cr2);
//Vertical DashDot line of the circle with diameter 25
Line vertLineLeftCircle = new Line(-50, 5, -50, -30);
vertLineLeftCircle.LineTypeName = DashDot;
vertLineLeftCircle.LineTypeMethod = colorMethodType.byEntity;
//Vertical DashDot line of the hexagon
Line vertLineHex = new Line(0, 12, 0, -12);
vertLineLeftCircle.LineTypeName = DashDot;
vertLineLeftCircle.LineTypeMethod = colorMethodType.byEntity;
//copy1 is the mirrored on YZ axis tangentLeft clone
Line copy1 = (Line)tangentLeft.Clone();
Line copy2 = (Line)l1.Clone();
Plane planeYZ = Plane.YZ;
Plane planeXZ = Plane.XZ;
planeYZ.Translate(-50, 0);
planeXZ.Translate(-50, 0);
Mirror mirrorYZ = new Mirror(planeYZ);
Mirror mirrorXZ = new Mirror(planeXZ);
copy1.TransformBy(mirrorYZ);
copy2.TransformBy(mirrorXZ);
Point3D[] intPoint2 = copy1.IntersectWith(cr2);
ICurve[] tangentLeftMirror = copy1.Offset(9, Vector3D.AxisZ);
//Used to find the center of the circle with diameter 9
ICurve[] middleTangentLeftMirror = copy1.Offset(4.5, Vector3D.AxisZ);
ICurve[] l1Mirror = copy2.Offset(4.5, Vector3D.AxisZ);
Point3D[] cr9LeftCenter = l1Mirror[0].IntersectWith(middleTangentLeftMirror[0]);
//Circle with diameter 9
Circle cr9 = new Circle(cr9LeftCenter[0], 4.5);
copy1.TrimBy(cr9.IntersectWith(copy1)[0], true);
tangentLeftMirror[0].TrimBy(cr9.IntersectWith(tangentLeftMirror[0])[0], true);
//Top left arc of diameter 9
Arc a1 = new Arc(cr9.Center, cr9.Radius, Math.PI * 2);
a1.TrimBy(tangentLeftMirror[0].StartPoint, false);
a1.TrimBy(copy1.StartPoint, true);
//Bottom left arc of cr2
Arc a2 = new Arc(cr2.Center, cr2.Radius, Math.PI * 2);
a2.TrimBy(tangentLeft.EndPoint, false);
a2.TrimBy(copy1.EndPoint, true);
tangentLeftMirror[0].ExtendAt(50);
//Bottom arc of the figure of radius 26
Arc a2Bottom;
Curve.Fillet(tangentLeftMirror[0], lowerLine, 26, false, false, true, true, out a2Bottom);
tangentLeftMirror[0].TrimBy(a2Bottom.IntersectWith(tangentLeftMirror[0])[0], true);
lowerLine.TrimBy(a2Bottom.IntersectWith(tangentLeftMirror[0])[0], true);
//Intersect point between vert line starting from x=10 and upperLine to draw dimension
Line constDimLine = new Line(10, 0, 10, 50);//Vert line starting from x=10
Point3D[] dimLine = constDimLine.IntersectWith(upperLine);
Entity[] entitiesToMirror = new Entity[] { hexagon, cr1, cr2 , l2, upperLine, lowerLine, tangentLeft, vertLineLeftCircle, copy1, (Entity)tangentLeftMirror[0], a1, a2, a2Bottom};
design1.Entities.Add(hexagon);
design1.Entities.Add(cr1, DimLayer);
design1.Entities.Add(l1, DimLayer);
design1.Entities.Add(cr2, DimLayer);
design1.Entities.Add(l2, DimLayer);
design1.Entities.Add(upperLine);
design1.Entities.Add(lowerLine);
design1.Entities.Add(tangentLeft);
design1.Entities.Add(vertLineLeftCircle, DimLayer);
design1.Entities.Add(vertLineHex, DimLayer);
design1.Entities.Add(copy1);
design1.Entities.Add((Entity)tangentLeftMirror[0]);
design1.Entities.Add(a1);
design1.Entities.Add(a2);
design1.Entities.Add(a2Bottom);
//for cycle to mirror every necessary entity on axis Y and X
foreach (Entity ent in entitiesToMirror)
{
Entity copy = (Entity)ent.Clone();
copy.Rotate(Math.PI, Vector3D.AxisZ);
design1.Entities.Add(copy);
}
Plane planexyR = Plane.XY;
planexyR.Rotate(Utility.DegToRad(30), Vector3D.AxisZ);
planexyR.Rotate(Utility.DegToRad(90), Vector3D.AxisZ);
planexyR.Rotate(Utility.DegToRad(180), Vector3D.AxisZ);
Plane planexyR2 = Plane.XY;
planexyR2.Rotate(Utility.DegToRad(26), Vector3D.AxisZ);
Point3D lowerIntPoint = l1.IntersectWith(lowerLine)[0];
design1.Entities.AddRange(new Entity[] {
new DiametricDim(cr2, new Point2D(-8, -8), TextHeight, Plane.XY),
new LinearDim(Plane.XY, new Point2D(-50, -30), new Point2D(50, -10), new Point2D(0, -50), TextHeight),
new LinearDim(planexyR, dimLine[0], lowerIntPoint, new Point3D(18, 10, 0), TextHeight),
new LinearDim(planexyR, new Point2D(-10, 5), new Point2D(10, 5), new Point2D(0, 14), TextHeight),
new RadialDim(a2Bottom, new Point2D(-25, -25), TextHeight, Plane.XY){ArrowsLocation = elementPositionType.Outside},
new AngularDim(Plane.XY, new Point2D(-50, -12.5), intPoint2[0], intPoint1[0], new Point2D(-50, -30), TextHeight),
new LinearDim(planexyR2, cr9.IntersectWith(copy1)[0], cr9.IntersectWith(tangentLeftMirror[0])[0], new Point3D(-80, 10, 0), TextHeight)
}, DimLayer);
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.Regen();
DrawFrame();
Utility function to draw the outline frame.
void DrawFrame()
{
string frameID = "900";
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);
}
Comments
Please sign in to leave a comment.