Questions similar to these appear in the Be Communities MicroStation Forum.

This page describes a solution to a user's question. The solution is implemented in a MicroStation VBA project.

Follow Line

Sometimes we want to pick a line in MicroStation and place some text, cell or other element at a point on that line. Other times we may want to choose a line and place some text, cell or other element at regular intervals along that line.

This VBA project answers both questions! You can choose to start it interactively, when some text is attached magically to a line you've chosen, and follows the cursor as you move the mouse. If you start the project in its normal mode, after prompting you to choose a linear element it places a cell at regular intervals along the element.

Linear Element

Each cell is rotated at its point of placement to the tangent of the linear element. Probably easier to visualise than read …

Linear Element with regularly spaced cells

VBA Project

You don't have to be a VBA whizz to use this macro. Skip to the download instructions and enjoy!

The project contains a number of VBA modules …

  1. modMain contains the main entry point and utility functions
  2. clsLinePicker is a class module that Implements ILocateCommandEvents. Its purpose is to let the MicroStation user choose a linear element
  3. clsLinearMarker is a class module whose job it is to place cells at regular intervals along the linear element
  4. clsInteractiveMarker is a class module that Implements IPrimitiveCommandEvents. It's used by clsLinePicker when started in interactive mode. Its job is cosmetic — it shows some text or a cell created in dynamics. In the class _Dynamics it finds the point on the linear element where a perpendicular from the current cursor location meets the element, calculates the tangent at that point, and places some text or a cell rotated by the tangent angle

clsLinearMarker Creates a B-Spline Curve

You may be surprised to see, on examining the code for clsLinearMarker, that it converts the chosen linear element to a B-Spline curve (VBA BSplineCurve class). That's because the BSplineCurve class has some useful methods for finding a point-at-distance and tangent-at-a-point. That combination makes it easy to calculate the location of the Nth marker along the linear element, and then create the rotated cell at that point.


Download

Download the Follow Line Tool

You can download the FollowLine MVBA project. The project includes the MVBA project FollowLine.mvba.

This code should work in both MicroStation V8i and MicroStation CONNECT.

Questions

Post questions about VBA to the MicroStation Programming Forum.