Edit text with VBA by coordinates

Hi 

I'm really new to VBA  and haven't really gotten a grip of how it works. I've managed to write some VBA-code for placing text by coordinates. 

Set oText = CreateTextElement1(Nothing, ooDate, point_text_Date, Matrix3dIdentity)
ActiveModelReference.AddElement oText

But now I would like to edit that text, and I have no clue how to. I've searched a lot after "edit text VBA microstation" and most answers is for when you need to search for some text, and replace it if found.

What I'm not really sure of is if I can select text in a particular coordinate by VBA, and then replace it by some text. Is there a command for selecting elements? 

I've also seen a lot about the element enumerator in these cases. Could that be used for coordinates as well?

Would it make a difference if that text was inside a cell? 

Running Openbuildigs, connect, update 5. 

Regards, 

Robert

Parents
  • Hi Robert,

    at first, a few recommendations:

    • Please read and follow MicroStation Programming forum best practices, especially how subject should be formatted and what information should always be shared.
    • This is general programming forum, not specific to MicroStation-based (power platfrom) products. Because (from reasons I do not know) there is no "building programming forum" and your question is quite general, I recommend to move it to MicroStation Programming forum. To move your post, use More > Move tool below your original post (do not duplicate your post somewhere else).
    • Always use Insert > Insert code tool when you want to share a code, even when it's one line only! To place the code as a plain unformatted text is like you want to make your text to be harder readable and especially when code is longer, it's a poisoning to read it and try to understand it.

    BTW There is no product named Openbuildings. To be developer require to be precise, so specify your product (as required by the best practices) exactly: OpenBuildings Designer CONNECT Edition Update 5, English version (?), probably build number 10.05.00.49. Is it correct? In the post subject it can shortened to [OBD U5 VBA], because there is no conflict with V8i names.

    I'm really new to VBA  and haven't really gotten a grip of how it works.

    I strongly recommend to first learn VBA and when you understand basics, to move to MicroStation VBA. Otherwise it will be painful progress with a lot of confusion. There are plenty of "general VBA tutorials available", also you can read Learning MicroStation VBA book. It's quite old, but the most of content is valid for CE also and it offers quick introduction into VBA langauge.

    But now I would like to edit that text, and I have no clue how to.

    It's simple:

    Dim te As TextElement
    
    ' Retrieve text element anyhow, e.g. using ID
    Set te = ActiveModelReference.GetElementByID(DLongFromLong(123456))
    
    ' Modify and rewrite text
    te.Text = "This is text"
    te.Rewrite

    What I'm not really sure of is if I can select text in a particular coordinate by VBA

    Again, please be exact. Too many sentences and still not quite clear what do you want to achieve and what the workflow should be:

    • Do you want to select text by a user? In such case implement ILocateCommandEvents object. It allows to select an element "by coordinates" selecting it by the user in a view.
    • Do you want to select all texts at specific coordinates? Use ElementScanCriteria with Range filter applied.
    if I can select text in a particular coordinate by VBA

    If you think about something like

    Dim te As TextElement
    
    ' Retrieve text element anyhow, e.g. using ID
    Set te = ActiveModelReference.GetElementByID(DLongFromLong(123456))
    
    ' Check whether coordinates are correct
    If (te.Origin.X = 1.2345 And te.Origin.Y = 9.8765) Then
        ' Do something
    End If

    it's incorrect and cannot be used. You cannot test decimal numbers euqality this way, never! When using element scanning, you should use Range criteria, and when individual coordinates are tested, they alwyas have to be tested in defined tolerance (e.g. using Point3dEqualTolerance).

    Would it make a difference if that text was inside a cell? 

    Do not break best practices! One question (issue / area) per one post. When you want to discuss another topic, create a new post.

    An answer in this case is: "Yes, it makes (huge) difference, but details depends how the cell will be selected (by user, using scan...)".

    With regards,

      Jan

  • Hi Jan, thanks for your reply. Haven't had a chance to try it till now. 

    Promise to be better at specifying my program in the future. 

    It's simple:

    I tried your code but I get a "type mismatch" error on the set te = ... line. Is there something else I have to do? 

    Again, please be exact. Too many sentences and still not quite clear what do you want to achieve and what the workflow should be:

    I would actually like to retrieve the object just by coordinates. Not elementID. After that maybe run a check that it's a textelement, and then change the text to whatever the user has chosen. 

    Reason is we have the legend text placed in our seed, and now we manually edit it en every sheetmodel. I'm trying to write something that will edit it for me. 

Reply
  • Hi Jan, thanks for your reply. Haven't had a chance to try it till now. 

    Promise to be better at specifying my program in the future. 

    It's simple:

    I tried your code but I get a "type mismatch" error on the set te = ... line. Is there something else I have to do? 

    Again, please be exact. Too many sentences and still not quite clear what do you want to achieve and what the workflow should be:

    I would actually like to retrieve the object just by coordinates. Not elementID. After that maybe run a check that it's a textelement, and then change the text to whatever the user has chosen. 

    Reason is we have the legend text placed in our seed, and now we manually edit it en every sheetmodel. I'm trying to write something that will edit it for me. 

Children