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!
The VBA project is available to download. The core components are described below.
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
Keyin …
vba run [SwingArrow]modMain.Main
Follow the prompts! You need to place three data points …
The Main()
VBA subroutine is in module modMain
.
All other code is contained in the class module clsSwingArrowCreator
.
The Main()
subroutine starts a MicroStation VBA primitive command class clsSwingArrowCreator
,
in the simple statement …
CommandState.StartPrimitive New clsSwingArrowCreator
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 …
Keyin
DataPoint
Reset
Cleanup
Dynamics
Start
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.
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.
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 …
CommandState.StartDefaultCommand
.
The Datapoint event is called three times in this example …
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.
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.
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.