
// sets model units in millimeters
design1.Units = linearUnitsType.Millimeters;
double
hBoxWidth = 50,
hBoxHeight = 140,
hBoxExtr = 10;
//VerticalBox Dimensions
double
vBoxSideBig = 55.5,
vBoxTop = 50,
vBoxSideSmall = 8,
vBoxRadius = 18;
//Slot Dimensions
double
slotOuterHeight = 25,
slotOuterExtrNeg = 12.5,
slotOuterExtrPos = 22.5,
slotOuterRadius = 25,
slotInnerRadius = 10;
//Circle Dimensions
double
circleOuterRadius = 25,
circleInnerRadius = 12.5,
circleExtr = 30;
//Creating the horizontal box
CompositeCurve hBoxCurve = CompositeCurve.CreateRectangle(-hBoxWidth / 2, 0, hBoxWidth, hBoxHeight, 0, false);
Region hBoxRegion = new Region(hBoxCurve);
Brep ext1 = hBoxRegion.ExtrudeAsBrep(Vector3D.AxisZ * hBoxExtr);
//Creating the vertical box
Line l1, l5, l3, l4, l0, l2;
Arc a;
l1 = new Line(Plane.YZ, 0, vBoxSideBig, circleOuterRadius * 2, vBoxSideBig);
l0 = new Line(Plane.YZ, 0, 0, 0, vBoxSideBig);
l4 = new Line(Plane.YZ, hBoxHeight, 0, hBoxHeight, vBoxSideSmall);
l2 = (Line)l0.Offset(vBoxTop, Vector3D.AxisX);
l5 = new Line(Plane.YZ, 0, 0, hBoxHeight, 0);
l3 = (Line)l5.Offset(vBoxSideSmall, Vector3D.AxisX * -1);
Curve.Fillet(l2, l3, vBoxRadius, false, true, true, true, out a);
CompositeCurve vbC = new CompositeCurve(l1, l0, l2, l4, l5, l3, a);
Region vbR = new Region(vbC);
vbR.Translate(Vector3D.AxisZ * hBoxExtr);
ext1.ExtrudeAdd(vbR, new Interval(-hBoxExtr / 2, hBoxExtr / 2));
//Creating the extruded slot
CompositeCurve sC = CompositeCurve.CreateSlot(Plane.XY, slotOuterHeight, slotOuterRadius, true);
sC.Rotate(devDept.Geometry.Utility.DegToRad(90), Vector3D.AxisZ);
sC.Translate(Vector3D.AxisY * (hBoxHeight + slotOuterHeight / 2));
Region sR = new Region(sC);
ext1.ExtrudeAdd(sR, new Interval(-slotOuterExtrNeg, slotOuterExtrPos));
//Creating the extruded circle
Circle c0 = new Circle(Plane.YZ, new Point2D(circleOuterRadius, vBoxSideBig + hBoxExtr), circleOuterRadius);
CompositeCurve c0C = new CompositeCurve(c0);
Region c0R = new Region(c0C);
ext1.ExtrudeAdd(c0R, new Interval(-circleExtr / 2, circleExtr / 2));
//Drilling the slot shaped hole
CompositeCurve shC = CompositeCurve.CreateSlot(Plane.XY, slotOuterHeight, slotInnerRadius, true);
shC.Rotate(devDept.Geometry.Utility.DegToRad(90), Vector3D.AxisZ);
shC.Translate(Vector3D.AxisY * (hBoxHeight + slotOuterHeight / 2));
Region shR = new Region(shC);
ext1.ExtrudeRemove(shR, new Interval(-slotOuterExtrNeg, slotOuterExtrPos));
//Drilling the circular hole
Circle c1 = new Circle(Plane.YZ, new Point2D(circleOuterRadius, vBoxSideBig + hBoxExtr), circleInnerRadius);
CompositeCurve c1C = new CompositeCurve(c1);
Region c1R = new Region(c1C);
ext1.ExtrudeRemove(c1R, new Interval(-circleExtr / 2, circleExtr / 2));
//Faces color
int[] faces0 = { 17, 18, 19, 20, 23 };
int[] faces1 = { 9, 10, 21, 22 };
foreach (int index in faces0)
{
ext1.Faces[index].Color = Color.GhostWhite;
}
foreach (int index in faces1)
{
ext1.Faces[index].Color = Color.DarkGray;
}
//Adding to Entities
ext1.Rotate(devDept.Geometry.Utility.DegToRad(180), Vector3D.AxisZ);
design1.Entities.Add(ext1, Color.Gold);
// Viewport setup
design1.RootBlock.Units = linearUnitsType.Millimeters;
design1.ZoomFit();
design1.ActiveViewport.Grid.Visible = false; // Hide grid
design1.ActiveViewport.OriginSymbol.Visible = false; // Hide origin
Drawing

// Creating a new sheet
Sheet sheet1 = new Sheet(linearUnitsType.Millimeters, 420, 297, "Sheet 1", angleProjectionType.FirstAngle); // Europe standard
// Getting the title block for A3 Iso standard format
BlockReference br = sheet1.BuildA3ISO(out Block a3Block, "A3_ISO");
// Initializing title block's attributes
br.Attributes["Title"] = new AttributeReference("My First Sheet");
br.Attributes["Format"] = new AttributeReference("A3");
br.Attributes["DwgNo"] = new AttributeReference("Root");
br.Attributes["Scale"] = new AttributeReference("SCALE: 1:2");
br.Attributes["Sheet"] = new AttributeReference("SHEET 1 OF 1");
// Adding the block related to the title block to the Blocks collection
drawing1.Blocks.Add(a3Block);
// Adding its reference to the sheet
sheet1.Entities.Add(br);
// Adding the sheet to the Sheets collection
drawing1.Sheets.Add(sheet1);
// Setitng the sheet as the active one
drawing1.ActiveSheet = sheet1;
// Refreshing the control
drawing1.Invalidate();
Point2D p0 = new Point2D(315, 232.75);
Point2D p1 = new Point2D(105 + 20, 232.75);
Point2D p2 = new Point2D(105 + 20, 130);
Point2D p3 = new Point2D(315, 130);
VectorView vectorViewT = new VectorView(p3.X, p3.Y, viewType.Top, .5, "Top Vector View")
{
HiddenSegments = true
};
VectorView vectorViewF = new VectorView(p0.X, p0.Y, viewType.Front, .5, "Front Vector View")
{
HiddenSegments = true
};
VectorView vectorViewR = new VectorView(p1.X, p1.Y, viewType.Right, .5, "Right Vector View")
{
HiddenSegments = true
};
RasterView rasterView = new RasterView(p2.X, p2.Y, viewType.Trimetric, .5, "Trimetric Raster View");
//Adding view's placeholders
sheet1.AddViewPlaceHolder(vectorViewT, design1, drawing1, "Top Vector View");
sheet1.AddViewPlaceHolder(vectorViewF, design1, drawing1, "Front Vector View");
sheet1.AddViewPlaceHolder(vectorViewR, design1, drawing1, "Right Vector View");
sheet1.AddViewPlaceHolder(rasterView, design1, drawing1, "Trimetric Raster View");
//Setting up the layers
const string Dim = "Dim";
const string Text = "Text";
drawing1.Layers.Add(Dim);
drawing1.Layers.Add(Text);
//Total Dimensions
double totalL = hBoxHeight + slotOuterHeight + slotOuterRadius;
double totalH = slotOuterExtrNeg + hBoxExtr + vBoxSideBig + circleOuterRadius;
double totalW = hBoxWidth;
//Text
Text t2 = new Text(0, totalL / 2 + 20, 0, "Top View", 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);//Top Caption
drawing1.Blocks[2].Entities.Add(t2, Text);
Text t3 = new Text(0, totalH / 2 + 20, 0, "Front View", 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);//Front Caption
drawing1.Blocks[3].Entities.Add(t3, Text);
Text t4 = new Text(0, totalH / 2 + 20, 0, "Right View", 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);//Right Caption
drawing1.Blocks[4].Entities.Add(t4, Text);
//Adding Top View Dimensions to the scene
Point2D p0T = new Point2D(-totalL / 2, 0);
Point2D p1T = new Point2D(+totalL / 2, 0);
Plane plT = new Plane(Point3D.Origin, Vector3D.AxisY, new Vector3D(-1, 0, 0));
drawing1.Blocks[2].Entities.Add(new LinearDim(plT, p0T, p1T, new Point2D(0, -(totalW / 2) - 20), 6), Dim);
//Adding Front View Dimensions to the scene
Point2D p0F = new Point2D(-totalW / 2, -totalH / 2);
Point2D p1F = new Point2D(totalW / 2, -totalH / 2);
drawing1.Blocks[3].Entities.Add(new LinearDim(Plane.XY, p0F, p1F, new Point2D(0, -(totalH / 2) - 20), 6), Dim);
//Adding Right View Dimensions to the scene
Point2D p0R = new Point2D(-totalH / 2, totalL / 2 - slotOuterHeight - 2 * slotOuterRadius);
Point2D p1R = new Point2D(totalH / 2, -totalL / 2 + circleOuterRadius);
Plane plR = new Plane(Point3D.Origin, Vector3D.AxisY, -1 * Vector3D.AxisX);
drawing1.Blocks[4].Entities.Add(new LinearDim(plR, p0R, p1R, new Point2D(0, -(totalL / 2) - 20), 6), Dim);
drawing1.Rebuild(design1);

Comments
Please sign in to leave a comment.