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 VBA?

A Create a class module that implements IPrimitiveCommandEvents. Use a member variable to store an elastic array of Point3d, and another member variable to track how many points the user has supplied.

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 Implements IPrimitiveCommandEvents by providing a number of methods that MicroStation calls when certain events happen. Events that are interesting in this example are …

IPrimitiveCommandEvents_Start

Initialise our variables and issue a prompt to the user.

IPrimitiveCommandEvents_DataPoint

Store the Point3d in our array of vertices, and increment the vertex count.

IPrimitiveCommandEvents_Dynamics

Create a temporary shape from our array of vertices and the current cursor position. Each time the user moves the mouse, MicroStation calls this subroutine to draw a new shape.

IPrimitiveCommandEvents_Reset

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

Example VBA Project

The CreateShape VBA Project is available in this ZIP file. Unpack the ZIP file and put CreateShape2.mvba somewhere where MicroStation can find it, such as C:\Program Files\Bentley\Workspace\Standards\vba.

You can run the sample using the keyin …
vba run [CreateShape2]CreateShapeMain.Main


Other Technologies for MicroStation Developers

Create Shape using MstnPlatformNet

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

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

Create Shape using MicroStationAPI

If you're interested in moving from VBA to C++, then the MicroStationAPI will help. The MicroStationAPI arrived with MicroStation CONNECT, and is a first-class C++ interface. It's a development and fusion of the MicroStation Development Library (MDL) and the MicroStationAPI provided with the SDK of MicroStation V8i.

See this article about how to create a shape with C++ using the MicroStationAPI.