This article is about MicroStation® Visual Basic for Applications (VBA). It's written for developers using Bentley Systems MicroStation. Questions similar to this appear on the Be Communities Forums. This problem appeared in the MicroStation Programming Forum.

Architects and interior designers like to annotate plans with swing arrows. A swing arrow indicates which way a door, or window, is intended to swing when opened.

Q   How can I draw a swing arrow using MicroStation?

A   MicroStation does not provide any tool to generate a swing arrow. The nearest you can get, without programming, is a cell. A cell can be rotated, flipped and scaled, so it probably comes close to your requirements.

However, the person who posted this question to the Be Communities Forums wanted to replicate functionality developed eons ago with MicroStation user commands (UCMs). We've posted the solution here, to show that anything a UCM can do, VBA can do better!

Swing Arrows

The VBA project is available to download. The core components are described below.

Main Entry Point

The Main() subroutine does very little other than to start the primitive class that does the work. To run the example, type the following MicroStation key-in …
vba run [SwingArrow]modMain.Main

How to place a Swing Arrow

Keyin …
vba run [SwingArrow]modMain.Main

Follow the prompts! You need to place three data points …

  1. The centre point of the arrow
  2. A data point at the start point (tail) of the arrow
    • This point determines the radius of the arrow and its start angle
  3. A data point at the end point (head) of the arrow
    • This point determines ending angle of the arrow

The Main() VBA subroutine is in module modMain. All other code is contained in the class module clsSwingArrowCreator.

Place an Arc Interactively

The Main() subroutine starts a MicroStation VBA primitive command class clsSwingArrowCreator, in the simple statement …
CommandState.StartPrimitive New clsSwingArrowCreator

Swing Arrow Creator Class

The Swing Arrow Creator Class is a VBA class that implements MicroStation's primitive command events interface. Almost the first line in the class code is the statement …
Implements IPrimitiveCommandEvents

A class that Implements IPrimitiveCommandEvents must have a set of subroutines that match the interface expections. In this case, you must write the following …

Although you must write each subroutine, you don't necessarily have to write any useful code inside each subroutine. Some are there for less usual purposes. We'll focus here on the IPrimitiveCommandEvents_Start, IPrimitiveCommandEvents_Dynamics and IPrimitiveCommandEvents_DataPoint subroutines.

Start Event

The Start event is fired when you first invoke your primitive class. This is a good time to issue prompts to your user, to inform her that the MicroStation state engine has started and is waiting for her to do something.

Datapoint Event

The Datapoint event is called automatically by MicroStation once your command has started, but after the Start event. When all other processing is complete, MicroStation will repeatedly call this subroutine until you tell it otherwise. Ways of stopping a primitive command are …

The Datapoint event is called three times in this example …

  1. To capture the centre of the circular arc that forms the skeleton of the arrow
  2. To capture the start point of the arc
    • At this point we start dynamics, to show the user how the arrow looks while she decides where the third datapoint should be
  3. To capture the end point of the arc
    • At this point the arrow has been constructed to the user's satisfaction. We add the completed arrow to the active model, then restart the command

We create the arrow as a cell in class method ConstructArrow. This method creates the cell and returns it to us. In the third datapoint event, we use ActiveModelReference.AddElement oArrow to add the arrow to the active model. Adding the arrow to the model draws it automatically.

Dynamics Event

Once the first two points have been captured, we start dynamics. From now on, MicroStation calls our subroutine each time the mouse is moved. The subroutine receives the current mouse position, at which point we have sufficient data to construct an arrow.

We create the arrow as a cell in class method ConstructArrow. This method creates the cell and returns it to us. In the dynamics event, we use oArrow.Redraw drawMode to show the current arrow to the user.

Download VBA Swing Arrow Project

Download SwingArrow.ZIP

The above code is available in this MicroStation VBA project. Unpack the ZIP archive and copy SwingArrow.mvba to a location where MicroStation can find it. A good place to copy it would be  …\Workspace\Standards\vba. To run the demonstration and create some swing arrows, key the following into MicroStation's keyin dialog …

vba run [SwingArrow]modMain.Main

Now, follw the prompts.


Back to the VBA article index.