Hello,
I have a problem with placing text with vba at different text height and with values. The follwoing code snipset works well in MS V8i SS10 but in CONNECT I have no idea what ist going wrong.
Sub test() Dim TextElement As TextElement Dim Point As Point3d Point.X = 100 Point.Y = 100 Set TextElement = CreateTextElement1(Nothing, "my text", Point, Matrix3dIdentity) TextElement.Color = 6 TextElement.TextStyle.Height = 5 TextElement.TextStyle.Width = 5 Application.ActiveModelReference.AddElement TextElement TextElement.Redraw msdDrawingModeNormal End Sub
If I change the TextElement.TextStyle.Height or Width value the text will be placed at the same values as before.
best regards
Daniel
Hi Daniel,
Daniel Grohmann said:The follwoing code snipset
I think your code is a bit dirty and I see some mistakes and bad practices. They do not cause the problem you mentioned, but the code is ... not clean as it can be:
Daniel Grohmann said:The follwoing code snipset works well in MS V8i SS10 but in CONNECT I have no idea what ist going wrong
I am not sure why the behavior changed (I did not test V8i SS10), but when it has changed, it's probably bug.
On the other hand, TextStyle is a bit specific, it's often copied and applied, not referenced directly.
This code should work fine:
Public Sub PlaceText() Dim textOrigin As Point3d textOrigin = Point3dFromXYZ(2, 4, 0) Dim text As TextElement Set text = CreateTextElement1(Nothing, "My test text", textOrigin, Matrix3dIdentity) Dim txtStyle As TextStyle Set txtStyle = text.TextStyle txtStyle.Height = 6 txtStyle.Width = 3 text.TextStyle = txtStyle ActiveModelReference.AddElement text End Sub
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: Daniel Grohmann
Hi Jan,
thank you for your answers and sorry for the old code style. The vba files are more than 15 years old really.Your code works well within CONNECT U13. Beside the bad code style I figured out that your row number 14 was missing in our old vba.
Thanks again for your help.