6 Replies Latest reply on Aug 3, 2016 3:06 AM by Mikeconnors

    ProcessBook VBA Use Button to Only Open 1 Layer

    Mikeconnors

      Hi All,

       

      I have a pretty monotonous job which I need some help with to make a little more dynamic. I have one overview page with a list of 25 different locations, each location is a button with a link to a different Display with a list of alerts (a series of digital tags that flash red when 0). each location has essentially the same information on it so I pretty much have to build 25 of the same screen.

       

      What I would like to do instead is to only build 1 screen and have the data update with the relevant information when the corresponding button is clicked. the tags being used isn't in the AF so I can't use Element Relative so I was thinking of just creating 25 layers. So my question is, can you write some VBA code to open a new ProcessBook display but only make visible the layers you tell it to?

       

      Regards,

       

      Michael

        • Re: ProcessBook VBA Use Button to Only Open 1 Layer
          kduffy

          Hi Michael,

           

          VBA is always the perfect way to add some spice to your job

           

          You can use the buttons to call some macros that set the .visible property for each of the layers.

           

          For example, here's a display with a square and circle on layers 1 and 2, and then 4 text boxes. You can use buttons, but this was the fastest way for me to show you an example before I have to head home for the day:

          layout of the display.png

           

          I then clicked on "hide layer 1" to get rid of the circle:

          hid layer 1.png

           

          next, I clicked on "show layer 1" to get the circle back, and "hide layer 2" to get rid of the rectangle:

          show 1 hid 2.png

           

          This is the code I'm using in VBA. Notice the text box names in the first screenshot (to use text boxes in VBA, you need to right click on them > "Enable Scripting". Shouldn't matter for you though since you're using buttons instead).

           

          Private Sub Text1_Click(ByVal lvarX As Long, ByVal lvarY As Long)
               ThisDisplay.Layers.Item(1).Visible = False
          End Sub
          
          Private Sub Text2_Click(ByVal lvarX As Long, ByVal lvarY As Long)
               ThisDisplay.Layers.Item(2).Visible = False
          End Sub
          
          Private Sub Text3_Click(ByVal lvarX As Long, ByVal lvarY As Long)
               ThisDisplay.Layers.Item(1).Visible = True
          End Sub
          
          Private Sub Text4_Click(ByVal lvarX As Long, ByVal lvarY As Long)
               ThisDisplay.Layers.Item(2).Visible = True
          End Sub
          

           

          You should be able to add some logic to check the .visible property of the layer and then set it to the opposite so your macros are cleaner, but this is the main concept.

           

          Let us know if you're able to get it from this or would like some clarification.

           

          Kelsey

            • Re: ProcessBook VBA Use Button to Only Open 1 Layer
              Mikeconnors

              Hi Kelsey,

               

              Thanks for such a quick response, and clear description of your answer. this is a really simple way to go about it. Do you know if it is possible to do this from a button on a different display though? Say that the hide/show layer text is on a different display and when clicked, they still mange  to show the corresponding shape in a different display?

               

              Regards,

               

              Michael

                • Re: ProcessBook VBA Use Button to Only Open 1 Layer
                  kduffy

                  For sure, you can have one display with the buttons, and assign a different macro to each button.

                  define the buttons.png

                   

                  The macro itself first checks to see if the display with the layers exists within the set of open displays. If it does, it sets it as the active display. If it doesn't, it will open it.

                  Then, it hides all the layers on that display, then finally it activates the one layer you would like.

                   

                  Sub openLayer1()
                  
                  
                      Dim thisDis As Display
                      Dim d As Display
                      Dim isClosed As Boolean
                  
                      isClosed = True
                      
                      For Each thisDis In Application.Displays
                          If thisDis.Path = "C:\users\kduffy\desktop\PS 14184.pdi" Then
                              isClosed = False
                              Set d = thisDis
                              d.Activate
                          End If
                      Next thisDis
                      
                      If isClosed Then
                          Set d = Application.Displays.Open("C:\users\kduffy\desktop\PS 14184.pdi", True)
                      End If
                      
                      Dim thisLay As Layer
                      
                      For Each thisLay In d.Layers
                          thisLay.Visible = False
                      Next thisLay
                          
                      d.Layers(1).Visible = True
                  
                  
                  End Sub
                  

                   

                  The second layer button is the exact same code as the first one, but with this at the end :

                   

                  d.Layers(2).Visible = True
                  

                   

                  You could trim this down by either adding another function that handles the opening of the display, activating it, and hiding its layers so you don't have to copy and paste that chunk 25 times; or you can even have one button and a text box where you type in the layer number you want visible. Then the call would be something like:

                   

                  d.layers(textbox.contents).Visible = true
                  

                   

                  but I haven't tested that out on my machine, so no promises that it works straight away.

                   

                  Let me know if this works.

                   

                  Kelsey

                  1 of 1 people found this helpful