MstnPlatformNet |
This article is for C# developers who want to write an application for MicroStation CONNECT. It describes DGN element mensuration — a way to extract metrics such as length, area and volume. This is not a complete application: rather, it describes what might otherwise be a non-intuitive approach to solve a problem.
If you want to ask questions about C# development for MicroStation CONNECT, post your question to the MicroStation Programming Forum.
This article clarifies the process of finding element metrics — length, area or volume — using the .NET API. The .NET API is huge, and delivered in multiple assemblies (Windows DLLs) and documented in several help files …
The help files are not cross-referenced. Sometimes it's tricky to discover the connection between one part of the API and another. This article leads you through the murk to find a solution to a task that would otherwise be simple.
If you're writing a C++ application for MicroStation, using the MicroStationAPI, then look at this article.
The MstnPlatformNet abstracts element mensuration from the primitive element classes to the CurveVector
class.
The CurveVector
class is documented in the BentleyGeometryNet help file.
Many primitive elements, such as a LineElement
, provide the
GetCurveVector()
method to extract a CurveVector
.
A CurveVector
can describe an open or closed path.
An open path is something like a line, line-string, arc or B-spline curve.
A closed path is something like a shape, ellipse or B-spline surface.
You can therefore use the CurveVector
class to measure a linear element or a closed area.
Get a CurveVector
from the DGN element, then calculate its length …
using Bentley.DgnPlatformNET; using Bentley.DgnPlatformNET.Elements; using Bentley.GeometryNET; CurvePathQuery q = CurvePathQuery.GetAsCurvePathQuery (element); // Check that this element supports CurvePathQuery if (null != q) { CurveVector vec = q.GetCurveVector(); // Check that we can extract a CurveVector if (null != vec) { double length = vec.SumOfLengths (); } }
Get a CurveVector
from the DGN element, then check that it's a closed boundary and calculate its area …
using Bentley.DgnPlatformNET; using Bentley.DgnPlatformNET.Elements; using Bentley.GeometryNET; CurvePathQuery q = CurvePathQuery.GetAsCurvePathQuery (element); // Check that this element supports CurvePathQuery if (null != q) { CurveVector vec = q.GetCurveVector(); // Check that we can extract a CurveVector if (null != vec && vec.IsClosedPath) { DPoint3d centroid; DVector3d normal; double area = 0.0; if (vec.CentroidNormalArea(out centroid, out normal, out area)) { // Do something with area } } }
At some time, you probably want to show the results of mensuration to the MicroStation user. Bentley Systems provide several formatters documented in DgnPlatformNet help. These formatters provide precise customisation possibilities of floating-point numbers and understand 1D, 2D and 3D quantities …
DistanceFormatter
class
AreaFormatter
class
VolumeFormatter
class
Those formatters are simple to use: set your display preferences (e.g. decimal separator, thousands separator,
precision, units etc.), then call the ToString (Double numberToFormat)
method …
using Bentley.DgnPlatformNET; double numberToFormat = 1234.456; DistanceFormatter formatter; // Initialised using active DGN model coordinate system ... modify formatter settings String formattedResult = formatter.ToString (numberToFormat);
Post questions about MicroStation programming to the MicroStation Programming Forum.
My thanks go to Jan Šlegr and Mauricio Terneus (Maury), frequent contributors to the MicroStation Programming Forum. They both offer indispensible nuggets of advice in response to questions posted to the MicroStation Programming Forum. They helped to demystify the MstnPlatformNET and BentleyGeometryNET APIs and provided hints that enabled me to write this article.