Introduction

Questions similar to this appear on the MicroStation Forum.

The question was posed by a MicroStation user. He wanted to measure the distance along a linear element to nearby circles or cells. A picture is worth a thousand words …

User requirement

Solution Provided by VBA

We have a line-string DGN element. Either side of the line-string are other DGN elements, in this case circles. User wants to measure the distance along the line to the projected point from the circle to the line.

Taking that description as a specification for software, we wrote a VBA macro to provide that functionality along with a user interface …

Measure Distance

To implement his requirement, we need to …

Notes for Developers

The UserForm provide two buttons (Pick Line and Pick Object) that start element choosers. Element choosers are VBA classes that Implement ILocateCommandEvents. User must pick a line before attempting to pick objects to be measured.

For each object picked, the macro calls subroutine GetDistanceAlongLine, which has two essential components …

Public Function GetDistanceAlongLine( _
		ByVal oLine As LineElement, _
		ByRef projectionPoint As Point3d, _
		ByRef hitPoint As Point3d) As Double
    GetDistanceAlongLine = 0
    hitPoint = oLine.ProjectPointOnPerpendicular(projectionPoint, Matrix3dIdentity)
    GetDistanceAlongLine = oLine.DistanceAtPoint(hitPoint)
End Function

Those methods are provided by many linear element classes (in this case a LineElement) …

The macro provides feedback to the user by filling a ListBox with information about each object and its distance along the line.


Download

Download Example VBA Project

A sample project is available. It includes code similar to that above and the VBA UserForm shown above. The macro is provided as freeware. It is not formally supported software. Use at your own risk.

You can download a ZIP file, and then extract MeasureDistanceAlongFromPerpendicular.mvba to a folder that MicroStation can find. A good place to put it would be ..\Workspace\Standards\macros, or any other folder specified in the MS_VBASEARCHDIRECTORIES configuration variable.

Start the macro with this MicroStation key-in …

vba run [MeasureDistanceAlongFromPerpendicular]modMain.Main

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.