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

Q

My first problem is how to allow an indefinite number of vertices when creating a polygon. How do I accumulate datapoints supplied by a user?

I would like to add dynamic "rubber banding" to my place shape command, so a MicroStation user can see the shape being created as they pick their points

How do I repond to the user's reset click to finish capturing points and create a polygon shape?

Place Fence userform

A To place a polygon, 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.

A To place a rectangle, create a class module that implements IPrimitiveCommandEvents. Capture two data points from the user, which we assume to be the opposing vertices of a diagonal drawn across the rectangle. From those two points we calculate the remaining vertices of the rectangle.

User Options

The UserForum provides placement options to modify the behaviour of the macro …

  1. Place Polygon
  2. Place Rectangle

Choose one or the other: VBA radio buttons enforce that rule.

Choose either or both options: VBA check boxes let you turn the option off or on.

Place Fence Classes

We supply two classes that each specify Implements IPrimitiveCommandEvents. One class lets you digitize an arbitrary number of points to create a polygon shape. The second class wants only two points, which form the vertices of a diagonal of the rectangular shape.

The example PlaceFence class provides a number of methods that MicroStation calls when certain events happen. Events that are interesting in this example are …

Polygon Shape

Polygon

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. Keep adding vertices until the user presses Reset.

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

Used when drawing a polygon. Create a shape from our array of vertices and, optionally, add it to the model. Next, create a fence from the shape.

Rectangular Shape

Rectangle

When placing a rectangle, if the vertex count is two then we are done. Calculate the remaining vertices of the rectangular shape. Create a shape from our array of vertices and, optionally, add it to the model. Next, create a fence from the shape.

IPrimitiveCommandEvents_Start

Initialise our variables and issue a prompt to the user.

IPrimitiveCommandEvents_DataPoint

Store two Point3d in our array of vertices. When we have two points, calculate the remaining vertices of a rectangle. Create a shape element and, optionally, add it to the active DGN model. Create a fence from the shape.

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

Used when drawing a polygon. Not used when creating a rectangle.

Example VBA Project

The PlaceFence VBA Project is available in this ZIP file. Unpack the ZIP file and put PlaceFence.mvba somewhere where MicroStation can find it, such as ..\Workspace\Standards\Macros\vba.

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