Questions about MicroStation appear in the Be Communities Forums.
This page lists some solutions to common MicroStation VBA (MVBA) problems. Tips are published as examples and are not necessarily working code.
This article was prompted by a question on the Be Communities MicroStation Programming Forum. The question asked was "Using MicroStation VBA, how do I identify a line element and then place points along it at various distances?" The distance values would come from an external source, such as an Excel worksheet.
This problem can be broken down into several tasks …
UserForm
) with controls for this application
A supplementary question is: "How do I calculate a tangent at each point on the line?"
At first sight, VBA's EvaluatePointTangent
looks just the job, but unfortunately that method
is broken at the time of writing (Spring 2016).
As a work-around, we use the MDL function mdlElmdscr_pointAtDistance
.
This suggestion was proposed and tested by Bentley Systems staffer
Artur Goldsweer on the Be Communities
MicroStation Programming Forum.
Thanks, Artur!
The code we write is conventional and follows the advice and examples you will find in
MicroStation VBA help,
and elsewhere on this web site.
The dialog's controls let a user perform the tasks necessary for this application …
To emulate the way in which MicroStation lets a user choose an element,
we write a VBA class that Implements ILocateCommandEvents
.
This tool should work with several element types: those that support the Element.PointAtDistance
method.
Those include the following types of element …
Element Type | VBA Enum |
---|---|
Arc | msdElementTypeArc |
B-Spline Curve | msdElementTypeBsplineCurve |
Complex String | msdElementTypeComplexString |
Line | msdElementTypeLine |
Line-String | msdElementTypeLineString |
We need to pass data between the VBA UserForm
and this locate class.
Another example,
MicroStation VBA Measure Line, shows how to exchange information with a locate class.
Because we want to place points at a distance along a line, it's important to know where we start. For that reason, we mark the line's start-point to provide a visual clue …
If the user wants to place points starting at the other end of the line, we provide a way to flip the start point …
Click the browse button to choose a CSV data file. Alternative, type the full file path into the box labelled File. Click the Place Points button to create a point for each distance data value read from the CSV file …
The format of the file is very simple — barely worth naming it a CSV file. It's nothing more than a list of distance measurements, each on a new line …
.5 1.1 2.3 3.1 4.7 5.8
Each value must be a positive decimal number. Non-numeric and zero or negative values will be rejected. When placing points, those distances greater than the element length will be ignored.
The number of points placed is shown in the dialog. The number placed might not match the number of points obtained from the CSV file. There are at least a couple of reasons why the point count may not be what you expect …
User expects to be able to undo an element creation operation …
You make such a transaction in MicroStation VBA undoable by bracketting the operation with CommandState
methods like this …
We put those commands in class
clsTransactionWrapper, described elsewhere.
Here, that class is used like this …
Dim oWrapper As New clsTransactionWrapper oWrapper.StartUndoableTransaction "Place Points Along Line" ... undoable element creation or modification operations ' The class Terminate method (oWrapper.Terminate) provides CommandState.StartDefaultCommand automatically
Download the Place Points Along Line VBA Project.
Once you've downloaded the ZIP archive, unpack it and copy the VBA project PlacePointsAlongLine.mvba
to a
well-known location.
A suitable place is ..\Organization\Standards\Macros
vba run [PlacePointsAlongLine]modMain.Main