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

Parents
  • 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

  • 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

  • I have to search texts with the class „construction“, change the text content and modify the class to „primary“

    You can do that using MicroStation's Select By tool.  Use that tool to create a selection set of text elements.  Then use the Change Attributes tool to switch class to Primary.

    MicroStation Change Attributes  tool

     
    Regards, Jon Summers
    LA Solutions

  • Jon, great hint, even if it can not solve the problem.
    Have never paid more attention to this tool and see just that it has great potential.

    It does not work on grouped items.
    I was able to use it to select some texts, but unfortunately not those that are grouped with other elements (ctrl+G).

    I think it's time to upload a sample file, to better understand the difficulty.

    The DGN contains the following texts:
     
    [Head1], [Head2], ..... [Head5]
    These texts have the class "construction" and were grouped together with border lines (which has the class "primary") to a first group (ctrl+G).

    and 5 more texts:
    Title1, Title 2, ..... Title5
    These texts have the class "primary" and have been grouped together with the first group (ctrl+G)

    (for information, Level 60 is locked)

    What I want do do:
    The texts [Head1] to [Head5] should be changed from Contruction to Primary.
    The text [Head1] to [Head5] content should be changed.
    The texts Title1 to Title5 content should be changed.

    ThanksExample for rename & class change.dgn

  • I was able to use it to select some texts, but unfortunately not those that are grouped with other elements (ctrl+G)

    When you create a group of elements (using Ctrl-G) you make an anonymous cell.  Jan mentioned that in his post but used the term unnamed cell.  So you need to consider text-in-cells to perform your reclassification.

    [VBA TextReplacer] does not work on grouped items

    That tool looks only at the top level elements in a cell.  Your DGN file has text elements in groups (anonymous cell) that are nested in other cells.  Consequently, the tool never finds them.

    It would be possible to modify the VBA code to enable the tool to search recursively through nested cells to find your text elements.  Alternatively, drop the top-level cell to reduce the level of nesting.  Unfortunately, you've locked level 60, which prevents me from dropping the cell.

     
    Regards, Jon Summers
    LA Solutions

  • Breaking up the nesting would not be a nice solution, as the groups are supposed to persist for several reasons.
    This would create additional work.
    The ability to change elements in nestings would be the goal
    The level lock can be easily removed in the level manager, or with the Keyin command: LEVEL SET LOCK TOGGLE 60 .....

    Finding a solution seems to be much more complicated than I initially thought.
    If it were not so many drawings, I would do it manually ..... :(

    Regards, Raphael

  • Finding a solution seems to be much more complicated than I initially thought

    That because your drawings are complex!  You have deeply-nested elements to find and modify.   Some elements are level-locked.

    The level lock can be easily removed in the level manager

    They are locked for a reason — under what circumstance is it OK  to unlock and modify them?  If the answer is: "Anybody can unlock them." then you must ask yourselves the question: "Why do we lock those elements?"  

    If it were not so many drawings, I would do it manually .....

    That's why we automate!  You must devise a strategy.  Write a specification for the goal of a mechanism to modify your drawings.  State what should happen to locked elements.  Once you have a specification you can decide how to implement it. 

    One solution is VBA, and I've published a VBA macro that makes a good starting point.  If your organisation has no VBA expertise then you should contract the development.  If your organisation has no money for development then I suggest that you revise your drawing policy to create simpler drawings that are easier to modify.

     
    Regards, Jon Summers
    LA Solutions

Reply
  • Finding a solution seems to be much more complicated than I initially thought

    That because your drawings are complex!  You have deeply-nested elements to find and modify.   Some elements are level-locked.

    The level lock can be easily removed in the level manager

    They are locked for a reason — under what circumstance is it OK  to unlock and modify them?  If the answer is: "Anybody can unlock them." then you must ask yourselves the question: "Why do we lock those elements?"  

    If it were not so many drawings, I would do it manually .....

    That's why we automate!  You must devise a strategy.  Write a specification for the goal of a mechanism to modify your drawings.  State what should happen to locked elements.  Once you have a specification you can decide how to implement it. 

    One solution is VBA, and I've published a VBA macro that makes a good starting point.  If your organisation has no VBA expertise then you should contract the development.  If your organisation has no money for development then I suggest that you revise your drawing policy to create simpler drawings that are easier to modify.

     
    Regards, Jon Summers
    LA Solutions

Children
No Data