Text

From Microstation VBA Wiki
Jump to: navigation, search

Placing text is much more dependent on ActiveSettings, so the command itself is pretty simple. It involves setting up a point (like lines or cells) and a rotation matrix, and giving the text to be placed, but otherwise most of the settings are stored in a property of ActiveSettings called TextStyle, which itself has a number of properties like Width, Height, and Justification.

First you have to set up a variable to hold the text element, Rotation Matrix and text string:

Dim oText as TextElement
Dim oMatrix as Matrix3d
Dim strText as String

Before creating the text elements, make sure the ActiveSettings are what you want. For Justification there are a bunch of built-in constants that can be used:

ActiveSettings.TextStyle.Justification = msdTextJustificationCenterBottom
ActiveSettings.TextStyle.Height = 2 * sca
ActiveSettings.TextStyle.Width = 2 * sca
oMatrix=Matrix3dIdentity

Then you store the element in your TextElement variable and add it to the drawing:

Set oText = CreateTextElement1(Nothing, strText, ptStart, oMatrix)
ActiveModelReference.AddElement oText

If you aren't rotating the text, you don't have to set up a matrix element and can just put Matrix3dIdentity in the function call.

Text Justification Settings

Text justification is set as shown above. Here are the choices:

msdTextJustificationLeftTop 
msdTextJustificationLeftCenter
msdTextJustificationLeftBottom 
msdTextJustificationCenterTop 
msdTextJustificationCenterCenter 
msdTextJustificationCenterBottom
msdTextJustificationRightTop
msdTextJustificationRightCenter  
msdTextJustificationRightBottom