The DgnPlatformNet API helps developers wanting to create custom applications for MicroStation® from Bentley Systems. We create a MicroStation application as a DLL, written using C# and built with the Microsoft tools provided with Visual Studio.
The Bentley Geometry API lives in .NET namespace Bentley.GeometryNET
and
is documented in the Bentley Geometry NET help file.
A related help file is Bentley Geometry NET Structs, which documents a huge range of classes and structs,
such as the ubiquitous DPoint3d
.
CurveVector
is a .NET class in the Bentley Geometry API.
It has many uses, particularly when assembling a collection of CurvePrimitive
objects.
In this example, I want to show how to convert a LineElement
to a CurveVector
en route to constructing a DRay3d
corresponding to each of LineElement
s
chosen by a user.
Using the two DRay3d
objects we can construct a fillet using
DEllipse3d.TryCircularFilletBetweenRays
…
I wrote this example to show how to construct a circular fillet between two lines.
The lines are represented in .NET by LineElement
and the fillet by an ArcElement
.
However, there's no direct method to construct a fillet from those DGN primitive elements.
Instead, we must move into the world of pure geometry.
We must first convert each LineElement
to a DRay3d
.
Then we can use DEllipse3d.TryCircularFilletBetweenRays
to make a fillet.
Finally, we convert the fillet to an ArcElement
.
using Bentley.GeometryNET; using Bentley.DgnPlatformNET; using Bentley.DgnPlatformNET.Elements; using Bentley.MstnPlatformNET;
ArcElement ConstructFilletElement (DPoint3d point) { DgnModel model = Session.Instance.GetActiveDgnModel(); LineElement l1 = (LineElement)model.FindElementById(FirstLineId); LineElement l2 = (LineElement)model.FindElementById(SecondLineId); DRay3d rayA = Geometry.MakeRayFromLineElement(l1); DRay3d rayB = Geometry.MakeRayFromLineElement(l2); DEllipse3d fillet; DVector3d v = new DVector3d(Intersection, point); double radius = v.Magnitude; if (DEllipse3d.TryCircularFilletBetweenRays(rayA, rayB, radius, out fillet)) { ArcElement filletElement = new ArcElement(model, null, fillet); return filletElement; } else { string s = $"Invalid parameters to construct fillet"; MessageCenter.Instance.ShowMessage(MessageType.Warning, s, s, MessageAlert.Balloon); } return null; }
DRay3d MakeRayFromLineElement(LineElement line) { DPoint3d a; DPoint3d b; CurveVector cv = line.GetCurveVector(); if (cv.GetStartEnd(out a, out b)) { return new DRay3d(a, b); } return new DRay3d(); }
The Create Fillet Example project for Visual Studio provides the above code.
The example provides a pick function, implemented in the CreateFilletTool
class,
which inherits from the .NET DgnElementSetTool
.
The Create Fillet Tool lets a user pick two LineElement
primitives.
Then it uses the code above to calculate a fillet, realised as a circular arc.
The fillet is drawn in dynamics, so its size and location changes as the user moves the mouse.
With the final datapoint, the fillet is added to the DGN model.
You can download the Create Fillet Example Visual Studio project.
The ZIP file includes the .NET project CreateFilletExample
.
mdl load CreateFilletExample
CREATEFILLETEXAMPLE PICK LINE
Post questions about C# and the DgnPlatformNet API to the MicroStation Programming Forum.