创建几何元素最终是通过IModel类的CreateElement接口实现的,参数设置好几何信息。示例代码如下:
//创建直线
Bentley.GeometryNET.Common.LineSegment geoLine = new Bentley.GeometryNET.Common.LineSegment(new DPoint3d(5 * duorPerMaster, 5 * duorPerMaster, 0), new DPoint3d(100 * duorPerMaster, 150 * duorPerMaster, 0));
IModelElement imLine = imodel.CreateElement(geoLine);
//创建圆
PlacementZX placeCirc = new PlacementZX(new DPoint3d(10 * duorPerMaster, 15 * duorPerMaster, 0));
Bentley.GeometryNET.Common.CircularArc geoCirc = new Bentley.GeometryNET.Common.CircularArc(placeCirc, 150 * duorPerMaster, Angle.Zero, Angle.TWOPI);
IModelElement imCirc = imodel.CreateElement(geoCirc);
//创建矩形
Bentley.GeometryNET.Common.Block geoBlock = new Bentley.GeometryNET.Common.Block(new PlacementZX(new DPoint3d(0, 0, 0)), new DPoint3d(3 * duorPerMaster, 4 * duorPerMaster, 0), new DPoint3d(300 * duorPerMaster, 400 * duorPerMaster, 0), true);
IModelElement imBlock = imodel.CreateElement(geoBlock);
//创建多边形
Bentley.GeometryNET.Common.Polygon geoPoly = new Bentley.GeometryNET.Common.Polygon();
geoPoly.AddPoint(new DPoint3d(607 * duorPerMaster, -130 * duorPerMaster, 0));
geoPoly.AddPoint(new DPoint3d(697 * duorPerMaster, 25 * duorPerMaster, 0));
geoPoly.AddPoint(new DPoint3d(607 * duorPerMaster, 181 * duorPerMaster, 0));
geoPoly.AddPoint(new DPoint3d(427 * duorPerMaster, 182 * duorPerMaster, 0));
geoPoly.AddPoint(new DPoint3d(337 * duorPerMaster, 26 * duorPerMaster, 0));
geoPoly.AddPoint(new DPoint3d(427 * duorPerMaster, -130 * duorPerMaster, 0));
IModelElement imPoly = imodel.CreateElement(geoPoly);
//创建弧
PlacementZX placeArc = new PlacementZX(new DPoint3d(800 * duorPerMaster, 15 * duorPerMaster, 0));
Bentley.GeometryNET.Common.CircularArc geoArc = new Bentley.GeometryNET.Common.CircularArc(placeArc, 150 * duorPerMaster, Angle.Zero, Angle.TWOPI * 0.08);
IModelElement imArc = imodel.CreateElement(geoArc);
//创建文字
DPoint3d textOrigin = new DPoint3d(1 * duorPerMaster, 4 * duorPerMaster, 0);
PlacementZX textPlacementPoint = new PlacementZX(textOrigin);
double characterSize = 100 * duorPerMaster;
Bentley.GeometryNET.Common.SingleLineText Geotext = new Bentley.GeometryNET.Common.SingleLineText(textPlacementPoint, "Hello i-model", "宋体", characterSize, characterSize, (int)TextElementJustification.CenterTop);
IModelElement imText = imodel.CreateElement(Geotext);
//创建线串
Bentley.GeometryNET.Common.LineString geoLineS = new Bentley.GeometryNET.Common.LineString();
geoLineS.AddPoint(new DPoint3d(900 * duorPerMaster, -100 * duorPerMaster, 0));
geoLineS.AddPoint(new DPoint3d(1000 * duorPerMaster, 10 * duorPerMaster, 0));
geoLineS.AddPoint(new DPoint3d(1100 * duorPerMaster, 200 * duorPerMaster, 0));
geoLineS.AddPoint(new DPoint3d(1200 * duorPerMaster, 250 * duorPerMaster, 0));
IModelElement imLineS = imodel.CreateElement(geoLineS);
//创建三维元素
DPoint3d point = new DPoint3d(1000 * duorPerMaster, 1200 * duorPerMaster, 1300 * duorPerMaster);
PlacementZX solidOrigin = new PlacementZX(point);
Bentley.GeometryNET.Common.SurfacePatch surfacepatch = new Bentley.GeometryNET.Common.SurfacePatch();
Bentley.GeometryNET.Common.CurveChain outer = new Bentley.GeometryNET.Common.CurveChain();
outer.AddCurve(new Bentley.GeometryNET.Common.CircularArc(solidOrigin, 500 * duorPerMaster, Angle.FromDegrees(0), Angle.FromDegrees(360)));
Bentley.GeometryNET.Common.CurveChain inner = new Bentley.GeometryNET.Common.CurveChain();
inner.AddCurve(new Bentley.GeometryNET.Common.CircularArc(solidOrigin, 100 * duorPerMaster, Angle.FromDegrees(0), Angle.FromDegrees(-360)));
surfacepatch.SetExteriorLoop(outer);
surfacepatch.AddHoleLoop(inner);
SolidBySweptSurface solid = new SolidBySweptSurface();
solid.SetBaseGeometry(surfacepatch);
Bentley.GeometryNET.Common.LineSegment extrusionPath = new Bentley.GeometryNET.Common.LineSegment(new DPoint3d(50 * duorPerMaster, 50 * duorPerMaster, 0), new DPoint3d(50 * duorPerMaster, 50 * duorPerMaster, 50 * duorPerMaster));
solid.SetRailCurve(extrusionPath);
IModelElement imSolid3d = imodel.CreateElement(solid);