Calculate Radius from Degree of Curve with VBA

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

This question is about converting a degree-of-curve value to a radius. Degree-of-curve is used in rail design in the US. It's similar to a Versine used in the UK and elsewhere.

Q How do I calculate an arc radius from a degree-of-curve value and apply it to a MicroStation tool?

A This article describes a MicroStation VBA project that shows how to perform the calculation and apply it to MicroStation's Fillet or Create Arc tool. The macro …

  1. Lets you specify a degree of curvature
  2. Calculates the radius from the degree of curvature
  3. Passes the new value to MicroStation's Fillet or Create Arc tool
Degree of Curve dialog

Here's the Fillet tool updated by this macro …

Create Fillet tool settings

Here's the Place Arc tool updated by this macro …

Place Arc tool settings

If you want to get started with using this macro, go to Download.

Notes for Programmers

The macro shows how to calculate radius from degree of curve …

Public Function CalculateRadius(ByVal degreeOfCurve As Double) As Double
    CalculateRadius = 50 / (Sin(Radians(degreeOfCurve / 2)))
End Function

Fillet Settings

The TCB variables we modify for a fillet are …

TCB Variables

The macro doesn't provide a tool to construct a fillet. That task is delegated to MicroStation's built-in fillet tool. However, the macro prepares MicroStation internal data. Those data are stored in the terminal control block (TCB), which is a chunk of public memory.

Those TCB variables are changed using VBA's SetCExpressionValue method …

SetCExpressionValue "tcb->fillet_radius", vtRadius, ""
SetCExpressionValue "tcb->msToolSettings.fillet.truncation", Me.cboTruncate.ListIndex, ""

Arc Settings

The place arc command belongs to the CONSGEOM application. We pass the radius to that app like this …

SetCExpressionValue "RadiusValue", CStr(m_dblRadius), "CONSGEOM"

It's best to lock the arc radius setting, which is otherwise cleared by a user mouse motion. We lock that setting using this rather obscure bit-twiddling …

Dim mask  As Long
mask = Not 8
mask = GetCExpressionValue("lockMask", "CONSGEOM") And mask
SetCExpressionValue "lockMask", mask Or 8, "CONSGEOM"
CadInputQueue.SendCommand "CONSGEOM CONSTRAIN RADIUS UPDATELOCK"

If you want to understand the above, read the note in the macro source code or post a question to the MicroStation Programming Forum.

Create Fillet Interactively using VBA

If you want to use VBA's IPrimitiveCommandEvents to draw a fillet interactively, then read this article.

Download CreateCentreLine.ZIP

Download the Degree of Curve ZIP archive, and unpack it to a suitable location such as ..\Workspace\Standards\macros. Start the macro using the key-in …

vba run [DegreeOfCurve]modMain.Main

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.