Introduction

The MicroStation Development Library (MDL) and MicroStationAPI provide APIs for 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 C++ compiler and linker provided with Visual Studio.

When editing your source code, you can choose whether to use Microsoft Visual Studio, Microsoft Visual Studio Code, or one of your favourite text editors.

When building your app, you can use Visual Studio or the Bentley Systems make (bmake) tools.

Create a Shape

Questions similar to this appear on the MicroStation Programming Forum. This problem appeared in the VBA discussion group.

Q How do I create a shape element using C++?

A Create a class module that inherits the DgnPrimitiveTool interface. Use a member variable to store an elastic array of DPoint3d using a Bentley vector: bvector<DPoint3d>. A bvector<> knows its size, so you don't have to store the point count in a variable.

With those pieces of data, you have enough information to display rubber banding as the user places datapoints.

Create Shape Class

The example CreateShape class uses the DgnPrimitiveTool interface by providing a number of methods that MicroStation calls when certain events happen. Events that are interesting in this example are …

_OnPostInstall

Initialise our variables and issue a prompt to the user.

_OnDataButton

Store the DPoint3d in our list (bvector<DPoint3d>) of vertices. There's no need to store the point count, because a bvector<> knows its own size.

_OnDynamicFrame

If the operator has placed the first point, then draw a line from that point to the current cursor position.

If the operator has place more than one point, create a temporary shape from our list of vertices and the current cursor position.

Each time the user moves the mouse, MicroStation calls this subroutine to draw a new element. The element is assigned the active settings.

_OnResetButton

Create a shape element from our list of vertices and add it to the model.

Example C++ Project

The CreateShape C++ Project is available in this ZIP file. Unpack the ZIP file and put CreatePrimitive.dll somewhere where MicroStation can find it, such as C:\Program Files\Bentley\MicroStation\mdlapps (or wherever your MS_MDLAPPS configuration variable is pointing).

You can run the sample using the keyin …
mdl load CreatePrimitive


Other Technologies for MicroStation Developers

Create Shape using MicroStation VBA

See this article about how to create a shape with VBA.

Create Shape using MstnPlatformNet

If you're interested in moving to C#, then the MstnPlatformNet will help. The MstnPlatformNet arrived with MicroStation CONNECT, and is a first-class C# interface.

See this article about how to create a shape with C# using the MstnPlatformNet.

Questions

Post questions about C++ and the MicroStationAPI to the MicroStation Programming Forum.