public static void LinestringArea(string unparsed) { double UPM = Program.GetActiveDgnModel().GetModelInfo().UorPerMaster; var activemodel = Program.GetActiveDgnModel(); var elements = Program.GetActiveDgnModel().GetGraphicElements(); foreach (var ele in elements) { if (ele.ElementType == BD.MSElementType.LineString) { BDE.LineStringElement linestring = ele as BDE.LineStringElement; var vector = linestring.GetCurveVector(); Bentley.GeometryNET.DPoint3d start, end; vector.GetStartEnd(out start, out end); if (start.Distance(end) < 0.1 * UPM) { var shapeele = DrawShapeFromLineString(linestring); if (shapeele != null) { shapeele.AddToModel(); } } } if (ele.ElementType == BD.MSElementType.ComplexString) { BDE.ComplexStringElement complexstringele = ele as BDE.ComplexStringElement; var cv = complexstringele.AsCurvePathEdit().GetCurveVector(); if (cv.Count > 1) { BG.DPoint3d DpStart1, DpEnd1, DpStart2, DpEnd2; cv.First().GetStartEnd(out DpStart1, out DpEnd1); cv.Last().GetStartEnd(out DpStart2, out DpEnd2); if (DpStart1.Distance(DpEnd2) < 0.1 * UPM) { var pointlist = new List <BG.DPoint3d>(); var complexshape = new BDE.ComplexShapeElement(activemodel, null); foreach (var pri in cv) { if (pri.TryGetLineString(pointlist)) { if (pointlist.Count > 2) { complexshape.AddComponentElement(new BDE.LineStringElement(activemodel, null, pointlist.ToArray())); } } } complexshape.AddComponentComplete(); complexshape.AddSolidFill(2, true); complexshape.AddToModel(); } } } } System.Windows.Forms.MessageBox.Show("Done!"); }
public static BDE.ShapeElement DrawShapeFromLineString(BDE.LineStringElement linestringele) { var pointlist = new List <BG.DPoint3d>(); var cv = linestringele.GetCurveVector(); if (cv.Count == 1 && cv.GetAt(0).TryGetLineString(pointlist)) { if (pointlist.Count > 2) { var shape = new BDE.ShapeElement(linestringele.DgnModel, null, pointlist.ToArray()); shape.AddSolidFill(2, true); return(shape); } } return(null); }