Questions similar to this appear on the Bentley Discussion Groups. These appeared in the VBA discussion group.
Q
A The Text Rotator VBA project answers those questions.
TextRotator is a freeware utility for MicroStation CONNECT and earlier versions of MicroStation.
TextRotator lets you pick DGN text elements (VBA TextElement
or TextNodeElement
).
Depending on the rotation method you choose, the text is rotated by the active angle,
a user-supplied angle, reset to zero rotation, or rotated to match the view containing the cursor.
The text rotator form (VBA UserForm
) provides a simple user interface.
Its option buttons let the user choose the rotation method.
The Rotate button is a command that starts a text locator primitive class (clsTextLocator
).
The clsTextLocator
implements the ILocateCommandEvents
interface.
You will find that interface documented in VBA help, along with examples.
When the user picks a text element, that element is rotated by the chosen angle.
Humans, like you, me and even computer programmers, think of degrees when we measure angles. However, geometric calculations are usually done using angles expressed in radians. Radians are more mathematically convenient than degrees.
When rotating an element, we need to calculate the rotation to apply.
Rotation is specified by a
matrix
(VBA Matrix3d
).
We must calculate your required rotation in degrees to radians, then convert radians to a Matrix3d
…
Dim rotation As Matrix3d rotation = Matrix3dFromVectorAndRotationAngle(viewAxis, radians)
"What's viewAxis
?" I hear you ask.
With a 2D DGN model, that's easy: the view axis is the Z axis.
With a 3D DGN model, it's more complicated because you can rotate a view to any orientation.
We need to find that orientation in order to figure out the view axis.
Fortunately, a MicroStation View
has a view plane.
Think of the plane as an invisible sheet parallel to your computer's screen.
A plane is identified by its normal, which is simple to find …
Public Function GetViewAxis(ByVal oView As View) As Point3d Dim plane As Plane3d plane = oView.ExtractFrontClippingPlane GetViewAxis = plane.Normal End Function
Examine the code in the Text Rotator project to see how we perform 2D and 3D rotation.
Examine the code in the Text Rotator project to see how we perform 2D and 3D rotation. You can read more about matrices, transforms and VBA.
The above code is available in this MicroStation
VBA project.
Unpack the ZIP archive and copy TextRotator.mvba
to a location where MicroStation
can find it.
A good place to copy it would be ..\Organization\Standards\macros
.
To start rotating text, enter the following into MicroStation's keyin dialog …
vba run [TextRotator]modMain.Main
Post questions about MicroStation programming to the MicroStation Programming Forum.