How to change the element class of text by batch processing or macro?

Hi,
I try to change a couple of texts an data fields by batch processing and if possible also change the element class for these texts from construction to primary.
If it could be important to know, the texts are grouped!

Changing text and data fields works well with this batch command:

MDL SILENTLOAD FINDREPLACETEXT,CHNGTXT CHANGE DIALOGTEXT

FIND DIALOG SEARCHSTRING [old text]
FIND DIALOG REPLACESTRING [new text]
CHANGE TEXT ALLFILTERED

but I could not change the class in any way... :(

Is there a possibility to to that?

I tried also to do it by a macro.
The rename part works well again, but not the part for the element class :(

The additional code (red) for the class changing seems not to work

Sub main
Dim startPoint As MbePoint
Dim point As MbePoint, point2 As MbePoint
' Start a command
MbeSendCommand "MDL KEYIN FINDREPLACETEXT,CHNGTXT CHANGE DIALOGTEXT"
' Send a keyin that can be a command string
MbeSendKeyin "FIND DIALOG PAN True"
MbeSendKeyin "FIND DIALOG ZOOM True"
MbeSendKeyin "FIND DIALOG ZOOMLEVEL 14"
MbeSendKeyin "FIND DIALOG SEARCHSTRING "
MbeSendKeyin "FIND DIALOG SEARCHSTRING old Text"
MbeSendKeyin "FIND DIALOG REPLACESTRING new Text"
MbeSendKeyin "CHANGE TEXT ALLFILTERED"

MbeSendKeyin "FIND DIALOG SEARCHSTRING "
MbeSendKeyin "FIND DIALOG SEARCHSTRING new Text"
MbeSendCommand "ACTIVE CLASS PRIMARY "
MbeSendCommand "CHANGE CLASS "

End Sub

I have to change the content and class for 10 textes (always the same) on a lot of drawings.....
perhaps another idea to do that?

Thanks
Regards, Raphael

  • MBE is an obsolete language with no ongoing support. You would be better off using VBA - there's a whole forum dedicated to Programming where you could find help.

    The Reason the Find/Replace text won't change the class of your text is that tool doesn't do that. It literally just finds text with the target string and changes that string. It doesn't select the text and it doesn't hold onto text. It's a one trick pony and it will only do that one trick - nothing else.

    You will need to find a way to put text elements into a selection set so that you can use a different tool to change class. VBA can do that easily. It's more than one or two lines, but it's a pretty basic function with a good amount of documentation. There may be a way to do it from a batch command invoking the Select By Attributes tool (which does have a "string" setting) but I don't know how to do that without looking into it more.

    MaryB

    Power GeoPak 08.11.09.918
    Power InRoads 08.11.09.918
    OpenRoads Designer 2021 R2

        

  • Note: This VBA is just for demonstration. Take a backup of your DGN before trying it out.
    Find the attached VBA which scans for Texts, TextNodes and if attribute Class = Construction, changes to Primary.ChangeTextElmClass.mvba

    VBA resources...

    Getting Started with Visual Basic

    Book: Learning MicroStation VBA

    Training: MicroStation VBA Programming Learning Path

          

  • Hello,
    First of all, big thanks for your help, I was not in the office for a few days and could only deal with the example VBA today.

    Leonard, thanks for this code. It works well for scanning and modifying text, but unfortunaly only if they are not grouped.
    I also appreciate your links to the VBA training documents, but unfortunately this is very complicated for me and can not really get started.
    With little success I have tried to understand the example code. However, making any changes seems impossible to me.

    So I want ask the question of whether there exist a practicable solution for grouped texts and data fields?
    Or have the groupings principial to be ungrouped before the element class of individual elements can be changed?
    For my purpose, I need to identify texts (and grouped texts) by content and modify only this. Not all elements of the model should be changed.
    I would be very grateful for any help.

    Regards, Raphael

  • So I want ask the question of whether there exist a practicable solution for grouped texts and data fields?

    There is no user tool in MicroStation that can be controled from outisde and to be used to change datafields inside text etc. Exactly because of these requirements a tool like VBA exists.

    With regards,

      Jan

  • Hi Jan,

    I have understand the problem and I know that there is no "toolbox" in Microstation solving my problem.....

    When I wrote "whether there exist a practicable solution"  I meant a solution with VBA.

    Since I have no idea about VBA, I do not know if VBA can solve the problem of grouped elements while changing the element class.....or if this fact will cause another additional problem.

    regards, Raphael

  • In VBA, you would need to take your "grouped" (complex) element and iterate through all of the sub-elements until you got to the text portion. Then you could apply your change to that text sub-element. This is how you would approach either text nodes or cells. Whether you would be allowed to change class of only a part of a text node ? I don't know that.

    Keep in mind also that Notes and Dimensions look like they have text sub-elements, but they don't. They are their own special types of elements, and the procedure for "getting in" to them and making text changes is a different type of procedure. And I can't tell you how to do that because I haven't figured it out yet.

    Hopefully someone here can assist you with that..

    MaryB

    Power GeoPak 08.11.09.918
    Power InRoads 08.11.09.918
    OpenRoads Designer 2021 R2

        

  • I do not know if VBA can solve the problem of grouped elements while changing the element class

    Because I don't know what "grouped elements" means to you, I can only say "probably yes".

    In MicroStation, elements can be grouped by several different ways and they can be applied with different element types:

    • Cells in general are a common way how to group elements
    • Ctrl+G creates unnamed cell
    • A shape with holes (group holes tool) creates another "special cell"
    • Graphic Group is old way how to group elements
    • There are Named Groups
    • There are also complex chain (called also complex string) and complex shape as wrote May

    Depending what type of grouping do you mean, VBA code will be different. And in some cases it's arguable whether it's valid to change element classes individuall: e.g. in cell elements can be completely different, but in complex chain all elements should use the same setting.

    I see as a problem to discuss two different topics (replace text content and changing element class) in one post.

    So general answer is "VBA is able to handle it", but as Mary wrote, there are elements like dimensions, notes with leaders etc. that are special and can require special approach ... or cannot be modified using VBA in a simple way.

    With regards,

      Jan

  • ohhhh, so many ways for groupes.... Slight smile

    With grouped texts I mean 2 or more textes selected and grouped with ctrl+G. Maybe also one or more textes and graphic elements (lines of a border) selected and grouped with ctrl+G.

    Not sure but I mean there are also sub-groups...., means a unnamed cell (ctrl+G) grouped with another one.

    Concerning the 2 topics...., actual I have to search texts with the class „construction“, change the text content and modify the class to „primary“. That‘‘s the reason why I ask for both.... But 2 separate solutions could in fact be better...., easyer to find a solution and also more flexible in use. Changing my texts step by step with 2 macros should not be a problem.

    So, what should I do....? Separate the topics.... or working on 2 separate solutions in this post?

    many thanks

    regards, Raphael

  • I meant a solution with VBA

    This VBA project shows how to find and replace text in plain text elements and in more complex structures, such as text nodes and cell elements:

    Text Search & Replace using MicroStation VBA

    That's a VBA project that you can use out-of-the-box.  The project is not protected, so you can see the source code.

    In your position I would take that project as a starting point and commission or employ a MicroStation VBA developer to modify it to perform the extra tasks you want.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Jon,

    Your idea is good, but unfortunately I do not know anybody here locally who could do something magical in VBA and hire a professional for this is unfortunately not possible in my company.

    With the thought, solving the 2 points (renaming and class changing) in 2 steps, I tried to use the textreplacer for renaming.
    Unfortunately, I come across an unexplainable problem.
    When I start the macro over the keyin command, I get after a few seconds an error message "Microstation stops working".
    I can not start this macro. With other VBA Macros I do not have this problem.
    Strangely, I could start the macro on the workstation of a colleague, with the same microstation installation, without problems.
    Any idea?

    Regards, Raphael