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 …
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 …
To implement his requirement, we need to …
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
) …
Element.ProjectPointOnPerpendicular
Projects an imaginary perpendicular line from the object's centre to the line to calculate a hitPoint
Element.DistanceAtPoint
measures the distance along the line from its start point to the hitPoint
ListBox
with information about each object
and its distance along the line.
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
Post questions about MicroStation programming to the MicroStation Programming Forum.