Let us define some useful constants first:
private const string
dimLayer = "Dimension",
thinLayer = "ThinLayer",
dashDot = "DashDot";
private const double textHeight = 5;
private const float defaultLineWeight = 2;
Here is the primary function:
void hook()
{
hookSetup();
hookFrame();
hookDrawing();
design1.SetView(viewType.Top);
design1.ZoomFit();
}
Here goes our setup function:
void hookSetup()
{
design1.Layers[0].LineWeight = defaultLineWeight;
design1.Layers.Add(dimLayer, Color.CornflowerBlue);
design1.Layers.Add(thinLayer, Color.Gray);
design1.LineTypes.Add(dashDot, new float[] { 15f, -5f, 1f, -5f });
}
We also need to prepare a frame:
void hookFrame()
{
const string frameTitle = "CAD Practice Drawing: hook";
const double halfWidth = 200, 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, "000", 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter)
});
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);
}
Finally, there's the drawing itself:
void hookDrawing()
{
// Top hole
const double
holeInternDiameter = 28,
holeExternDiameter = 60,
holeY = 113;
GCircle gc0 = new GCircle(0, holeY, 0, holeInternDiameter / 2);
GArc ga0 = new GArc(0, holeY, 0, holeExternDiameter / 2, -Math.PI / 2, Math.PI * 1.5);
// Right
const double
rightX = 40,
rightY = 83,
rightRadius = 20;
GArc ga1 = new GArc(rightX, rightY, 0, rightRadius, Math.PI / 2, Math.PI * 1.5);
Point3D a0a1Int = ga0.IntersectWith(ga1)[0];
ga0.TrimBy(a0a1Int, true);
ga1.TrimBy(a0a1Int, true);
// Bottom right
const double
bottomX = 6,
bottomRadius = 65,
bottomRightRadius = 46;
GArc ga2 = new GArc(bottomX + bottomRadius - bottomRightRadius, 0, 0, bottomRightRadius, 0, Math.PI / 2);
GLine ga1toa2 = UtilityEx.GetLinesTangentToTwoCircles(ga1, ga2)[0];
ga1.TrimBy(ga1toa2.StartPoint, false);
ga2.TrimBy(ga1toa2.EndPoint, false);
GArc ga3 = new GArc(bottomX, 0, 0, bottomRadius, Math.PI * 1.5, Math.PI * 2);
// Bottom
const double bottomInternalRadius = 25;
GArc ga4 = new GArc(0, 0, 0, bottomInternalRadius, -Math.PI, Math.PI / 2);
GLine ga0toa4 = UtilityEx.GetLinesTangentToTwoCircles(ga0, ga4)[2];
ga0.TrimBy(ga0toa4.StartPoint, false);
ga4.TrimBy(ga0toa4.EndPoint, false);
// Bottom left
const double
bottomLeftY = -5,
bottomLeftRadius = 60;
GArc ga5 = new GArc(bottomX, bottomLeftY, 0, bottomLeftRadius, Math.PI / 2, Math.PI * 1.5);
// Left
const double
leftX = -70,
leftPolarRadius = 37,
leftRadius = 8,
leftBigRadius = 45,
tangentCircleRadius = 45;
const double leftPolarAngle = Math.PI * 50 / 180;
GArc ga6 = new GArc(leftX + leftPolarRadius * Math.Cos(leftPolarAngle), leftPolarRadius * Math.Sin(leftPolarAngle), 0, leftRadius, 0, Math.PI * 3 / 2);
GArc ga7 = new GArc(leftX, 0, 0, leftBigRadius, 0, leftPolarAngle);
ga6.TrimBy(ga6.IntersectWith(ga7)[0], true);
GCircle gc1 = UtilityEx.GetCirclesTangentToTwoCircles(ga5, ga6, tangentCircleRadius, true)[0];
ga5.TrimBy(gc1.StartPoint, true);
ga6.TrimBy(gc1.EndPoint, false);
Arc a0 = new Arc(ga0),
a1 = new Arc(ga1),
a2 = new Arc(ga2),
a3 = new Arc(ga3),
a4 = new Arc(ga4),
a5 = new Arc(ga5),
a6 = new Arc(ga6),
a7 = new Arc(ga7);
Circle
c0 = new Circle(gc0),
c1 = new Circle(gc1);
Line
a1toa2 = new Line(ga1toa2),
a0toa4 = new Line(ga0toa4);
design1.Entities.AddRange(new Entity[] { c0, a0, a1, a2, a1toa2, a3, a4, a0toa4, a5, a6, c1, a7 });
const double DimOffset = 10, AxisOverflow = 5;
Plane verticalDimensions = new Plane(Point3D.Origin, Vector3D.AxisY, -1 * Vector3D.AxisX);
Plane Rotation = (Plane)Plane.XY.Clone();
Rotation.Rotate(leftPolarAngle, Vector3D.AxisZ);
design1.Entities.AddRange(new Entity[] {
// Linear dimensions
new LinearDim(Plane.XY, new Point2D(-holeInternDiameter / 2, holeY),
new Point2D(holeInternDiameter / 2, holeY), new Point2D(0, holeY + holeExternDiameter / 2 + DimOffset), textHeight),
new LinearDim(Plane.XY, new Point2D(-holeExternDiameter / 2, holeY),
new Point2D(holeExternDiameter / 2, holeY), new Point2D(0, holeY + holeExternDiameter / 2 + 2 * DimOffset), textHeight),
new LinearDim(verticalDimensions, new Point2D(0, 0),
new Point2D(holeY, 0), new Point2D(holeY / 2, - bottomX - bottomRadius - 2 * DimOffset), textHeight),
new LinearDim(verticalDimensions, new Point2D(0, -rightX),
new Point2D(rightY, -rightX), new Point2D(rightY / 2, - bottomX - bottomRadius - DimOffset), textHeight),
new LinearDim(Plane.XY, new Point2D(0, rightY),
new Point2D(rightX, rightY), new Point2D(rightX / 2, rightY - 2 * DimOffset), textHeight),
new LinearDim(Rotation, new Point2D(leftX * Math.Cos(leftPolarAngle), -leftX * Math.Sin(leftPolarAngle)),
new Point2D(leftX * Math.Cos(leftPolarAngle) + leftPolarRadius, -leftX * Math.Sin(leftPolarAngle)),
new Point2D(leftX * Math.Cos(leftPolarAngle) + leftPolarRadius / 2, -leftX * Math.Sin(leftPolarAngle) + 2 * DimOffset), textHeight),
new LinearDim(verticalDimensions, new Point2D(bottomLeftY, -bottomX), new Point2D(0, -bottomX), new Point2D(bottomLeftY / 2, -bottomX - DimOffset), textHeight),
new LinearDim(Plane.XY, new Point2D(0, 0), new Point2D(bottomX, 0), new Point2D(bottomX / 2, -4 * DimOffset), textHeight),
new LinearDim(Plane.XY, new Point2D(leftX, 0), new Point2D(0, 0), new Point2D(leftX / 2, - bottomLeftRadius - DimOffset), textHeight),
// Radial dimensions
new RadialDim(a1, new Point2D(-25, 10), textHeight),
new RadialDim(a2, new Point2D(20, 10), textHeight),
new RadialDim(a3, new Point2D(20, -40), textHeight),
new RadialDim(a4, new Point2D(-25, -30), textHeight) {
ArrowsLocation = elementPositionType.Outside
},
new RadialDim(a5, new Point2D(-20, -35), textHeight),
new RadialDim(a6, new Point2D(-10, 20), textHeight) {
ArrowsLocation = elementPositionType.Outside
},
new RadialDim(c1, new Point2D(25, 5), textHeight),
new RadialDim(a7, new Point2D(30, 10), textHeight),
// Angular dimension
new AngularDim(Plane.XY, ga7.Center, ga7.StartPoint, ga7.EndPoint, new Point2D(10, 20), textHeight)
{
ExtLineOffset = 0
}
}, dimLayer);
design1.Entities.AddRange(new Entity[] // axes
{
new Line(-holeExternDiameter / 2 - AxisOverflow, holeY, holeExternDiameter / 2 + AxisOverflow, holeY)
{
LineTypeMethod = colorMethodType.byEntity,
LineTypeName = dashDot
},
new Line(leftX - AxisOverflow, 0, bottomX + bottomRadius + AxisOverflow, 0)
{
LineTypeMethod = colorMethodType.byEntity,
LineTypeName = dashDot
},
new Line(0, holeY + holeExternDiameter / 2 + AxisOverflow, 0, -bottomRadius - AxisOverflow)
{
LineTypeMethod = colorMethodType.byEntity,
LineTypeName = dashDot
}
}, thinLayer);
}
Comments
Please sign in to leave a comment.