You are currently reviewing an older revision of this page.
Symptoms
During the revision of drawings, it is often necessary to adapt the alignment of all texts. This is a typical task for a VBA routine.
However, when changing the text orientation of the insertion of text (.Origin), it will sometimes automatically shift the text to an undesired location.
Troubleshooting Steps
This undesired shift can be slightly offset by the change in the orientation by using a VBA routine to push the text back to its original point. You can use a RangeBox here, which is the smallest rectangle bounding the text.
Here is an example for how to carry this process out. In the example, the text elements must be selected in advance.
Sub
textalignWithCorrection()
Dim
Ee
As
ElementEnumerator
pOriginOld
Point3d
pOriginNew
pOffset
Set
Ee = ActiveModelReference.GetSelectedElements
Do
While
Ee.MoveNext
If
Ee.Current.IsTextElement
Then
pOriginOld = Ee.Current.AsTextElement.Range.Low
Ee.Current.AsTextElement.TextStyle.Justification = msdTextJustificationCenterBottom
Ee.Current.Rewrite
pOriginNew = Ee.Current.AsTextElement.Range.Low
pOffset.x = pOriginOld.x - pOriginNew.x
pOffset.y = pOriginOld.y - pOriginNew.y
pOffset.Z = pOriginOld.Z - pOriginNew.Z
Ee.Current.AsTextElement.Move pOffset
End
Loop
In this example, all texts are aimed at the "bottom center" (msdTextJustificationCenterBottom)
The following (from VBA Help) is a list of all valid values for the orientation: