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.

Introduction

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.

Points along a Line

This problem can be broken down into several tasks …

Calculate Tangents

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!

VBA Help
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.

Show a Dialog

Place Points Dialog

The dialog's controls let a user perform the tasks necessary for this application …

Identify Suitable Element

Pick Line

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 Types that support Element.PointAtDistance
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.

Identify Start of Line

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 …

Mark Line Start Point

If the user wants to place points starting at the other end of the line, we provide a way to flip the start point …

Flip Line Start Point

Read Point Data from a File

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.

Place Points at a Distance along Line

Points Placed

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 …

  1. The CSV file is incorrectly formatted and no values are obtained
  2. The cell name — either the active point or the name you specify — is empty or the cell does not exist
  3. The values are obtained correctly, but one or more distances exceed the length of the line (i.e. they fall off the end of the line)

Place Points can be Undone

User expects to be able to undo an element creation operation …

Undo

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

Download the VBA Project

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