[CONNECT] U13 VBA Text Placement does not recognize TextStyle Height and Width Values

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

Parents
  • Hi Daniel,

    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:

    • Do not use the same variable names as classes names. Reading the code, is TextElement the class or the variable?
    • I am aware many VBA tutorials use PascalCase (first letter is capital) as variable naming style. In my opinion it's seriously bad idea and I see a huge amount of errors causing this strange rule. I recommend to use camelCase, so it's always clear whether it's the name of variable or Class.
    • Declare variable when it's necessary, never earlier (e.g. at the beginning of a sub)!
    • There is not single reason to redraw element when it's added to model. The last version, when elements were not displayed automatically was MicroStation V8 2004 Edition, which was 16 years ago.
    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

    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.

    best regards

    Daniel

Reply Children
No Data