MACRO "toggle TextNodes on views" setting all opened views ON or OFF

Hi,

I want to switch the view setting (showing TextNodes) on all my opened views to ON or to OFF by using "one" F-Key as toggle!
Regardless of how the view setting (view TextNodes) of different views are set.

I wrote a little macro with following code, but this is not an ideal solution, because it will only work well if all views have the same view settings at the beginning.

Is there a possibility to add a "if then else" routine to this code to check if a view is ON and set it to OFF and so on....., or another solution for this problem?

Sub main
    Dim startPoint As MbePoint
    Dim point As MbePoint, point2 As MbePoint

    MbeSendCommand "powerselector deselect"                 'Global unselect any Element Selection
    MbeSendCommand "set nodes toggle"

    startPoint.x = 0.000000#                                'Coordinates in Master Units for placing Cell
    startPoint.y = 0.000000#

    point.x = startPoint.x                                  'Send a data point to select view 1
    point.y = startPoint.y
    MbeSendDataPoint point, 1%

    point.x = startPoint.x                                  'Send a data point to select view 5
    point.y = startPoint.y
    MbeSendDataPoint point, 5%

    point.x = startPoint.x                                  'Send a data point to select view 6
    point.y = startPoint.y
    MbeSendDataPoint point, 6%

    MbeSendCommand "update all"


End Sub

Thanks for your help

Regards
Raphael

  • A couple of problems with this code...Microstation BASIC is a "dead" language. It hasn't been supported for some time, and may not even run at all in the near future releases. I'd suggest you invest a little time in Microstation VBA. It isn't much more difficult and more powerful.

    You want one command on one function key to set the Text Node View Attribute to be the same for all open views. OK.
    You want that single command on one function key to TOGGLE the Text Node Attributes for all Open views. OK.
    You want that single command on one function key to toggle SOME of the View Attributes and leave the others alone, based on their KNOWN starting value? OK...

    You want that single command on one function key to toggle SOME of the View Attributes and leave the others alone based on some UNKNOWN starting value? That's the one I'm not so sure about.

    I'm not sure how you would be able to tell that one-click command whether you want the Attribute ON or OFF and whether you are toggling a view or leaving it alone. 

    Either way, you will have FAR more luck if you post to the Programming Forum. They are far better versed in computer logic than I will ever be.

    MaryB

    Power GeoPak 08.11.09.918
    Power InRoads 08.11.09.918
    OpenRoads Designer 2021 R2

        

  • MaryB is correct that language is dead and if you want a program (i.e. VBA) to do this you would be best to post in the Programming forum. I am not a programmer  but, I remember way back when, there was a key-in to Toggle that switch, or turn them On/Off

    Currently you would have to use 2 Function keys. One for turning the Text Node display On, and one to turn them Off.

    The "SelView All" doesn't seem to work. So I had to use a different method to select the views.

    Set Nodes Off;xy=,,,1;xy=,,,2;xy=,,,3;xy=,,,4;xy=,,,5;xy=,,,6;xy=,,,7;xy=,,,8; Update All

    Set Nodes On;xy=,,,1;xy=,,,2;xy=,,,3;xy=,,,4;xy=,,,5;xy=,,,6;xy=,,,7;xy=,,,8; Update All

    The key-in's seemed to work in Connect U5. so they should also work in V8i also.

    I Hope This Helps Someone Reading This!  (Intergraph>PseudoStation>MicroStation user since 1980's)

  • Hi Raphael,

    you did not mention what MicroStation version you use, but I agree with Mary that to use MicroStation BASIC is not good solution. It was marked as obsolete in V8 2005 Edition (I guess), which means it's not supported anymore and from MicroStation 8.0 it's recommended to use MicroStation VBA.

    As Mary wrote, MicroStation BASIC has been removed in MicroStation CONNECT Edition, so any code written in this language is more or less wasted time.

    In MicroStation VBA, the code is quite simple:

    Option Explicit
    
    Public Sub SwitchOffTextNodeAttribute()
    
        Dim v As View
        
        For Each v In ActiveDesignFile.Views
            If v.IsOpen Then
                v.DisplaysTextNodes = False
                v.Redraw
            End If
        Next
    
    End Sub

    When your requirement "in all opened view" is removed and the attribute is switched off in all views including closed ones, the code is even simpler:

    Option Explicit
    
    Public Sub SwitchOffTextNodeAttribute2()
    
        Dim v As View
        
        For Each v In ActiveDesignFile.Views
            v.DisplaysTextNodes = False
            v.Redraw
        Next
    
    End Sub

    With regards,

      Jan

  • Hi all,

    Thanks for your help and the codes.
    I use MS V8i SS3 and it is clear to me that BASIC is "dead" and no longer popular here.
    But unfortunately, I have no idea of VBA programming and an attempt to deal with VBA was not particularly successful :(

    @Jan
    I could understand your codes and add it to a new VBA project for testing. Switching off the nodes works without problems.

    However, the question of the toggle function remains.
    An idea would be to read the view 1, to check whether the textnodes are switched on this view.
    Then on the basis of this information, programming a reversing function.

    For ex.:

    If on view 1 the textnodes are "true", during the first run of the macro all views will be swiched to textnodes "false"
    On a second run all views are "false" and would be switched to "true"......

    Is this possible and could anyone help me to write the correct code?

    Thanks a lot for your help

    Regards
    Raphael

  • Hi Raphael,

    Unknown said:
    But unfortunately, I have no idea of VBA programming and an attempt to deal with VBA was not particularly successful :(

    VBA development is easier than MicroStation BASIC, especially because of plenty of VBA tutorials (VBA basic are the same for all application variants like Excel VBA etc.). MicroStation VBA extension (object model) can be learned from MicroStation VBA help file, discussed questions or using Learning MicroStation VBA book (which is quite old, but still valid).

    Unknown said:
    For ex.: If on view 1 the textnode...

    This is not what you asked for originally. The difference is in "all view" request. How the macro should behave when at the beginning some view will display text nodes and others not? If the macro will switch on / off the attributes only (will invert their settings), it will not work as "switch off (or back to on) in all opened views".

    With regards,

      Jan

  • Hi Jan,

    Up to now, my macros was mainly be created by recording and less by programming :)
    I do not really look through VBA, with all the commands, variables and the right way to write the code lines......
    I've already tried it but without success.
    Perhaps a good tutorial for absolute beginners could help ...

    That my idea does not correspond to the initial question is right.
    That should be just an idea how I could get to the goal.
    The goal is to create a way to easily switch textnodes on and off, and due to the limitation of F-Keys, I would like to realize this via a toggle function on only one key.

    The main problem with the toggle is that when working with several views, the respective state per view can vary and be different.
    A "controled" on/off switching for all views with a toggle function is not possible without further tricks.

    My trick would be to read out the view 1 and then switch to the opposite value, but not only the view 1 but also set all the other views to the same value (false or true) for the text nodes view attribute.

    I hope I could explain it better now.

    Thanks
    Regards
    Raphael

  • Unknown said:
    Perhaps a good tutorial for absolute beginners could help ...

    The book I mentioned is exactly this in my opinion: It provides both intro to VBA itself, how VBA is implemented into MicroStation and chosen topics from MicroStation VBA. So it's like "all together" cookbook, which is not very good for advanced topics, but as the first reading, it's not bad.

    It's available both from Bentley and Amazon (and also few other shops).

    Unknown said:
    My trick would be to read out the view 1 and then switch to the opposite value, but not only the view 1 but also set all the other views to the same value (false or true) for the text nodes view attribute.

    Ok, it makes sense now ... it's about to define view 1 as "superior controller", where all other view will be set accordingly to the view 1.

    Regards,

      Jan

  • Unknown said:
    My macros was mainly be created by recording

    VBA Macro Recorder

    You can record a VBA macro!

     
    Regards, Jon Summers
    LA Solutions

  • Try this code:

    Public Sub SwitchOffTextNodeAttribute3()
    
        Dim textNodeAttributeStatus As Boolean
        
        If ActiveDesignFile.Views(1).DisplaysTextNodes = True Then
            textNodeAttributeStatus = False
        Else
            textNodeAttributeStatus = True
        End If
    
        Dim v As View
        
        For Each v In ActiveDesignFile.Views
            v.DisplaysTextNodes = textNodeAttributeStatus
            v.Redraw
        Next
    
    End Sub

    With regards,

      Jan

    Answer Verified By: Raphael :) 

  • Hi Jan,

    Is that crazy!

    Exactly what I want, and that with only few lines of code....
    I'm really happy!

    That motivate me and I will ask my boss for this VBA cooking book, soon will be Christmas..... :)

    many many THANKS to you and the others !
    Regards
    Raphael