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

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

Reply Children