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:
I then clicked on "hide layer 1" to get rid of the circle:
next, I clicked on "show layer 1" to get the circle back, and "hide layer 2" to get rid of the rectangle:
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.
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?
1 of 1 people found this helpful
For sure, you can have one display with the buttons, and assign a different macro to each button.
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.
that's exactly what I was after thanks!
I have another questions, I don't think it will be possible but it's worth a try, do you know if there is a way to do something like this that works when opened in Coresight? I know Coresight isn't compatible with VBA but maybe there is a work around? I know it's a stretch.
Thanks for your help!
2 of 2 people found this helpful
As for the Coresight portion, you're correct that it does not allow VBA within ProcessBook displays.
The truely recommended solution would be to implement and utilize the element relative features since Coresight has a lot of functionality built around it.
Another option, though, would be to use Coresight Extensibility. I personally have not used it before and I couldn't tell you exactly what to do, but there are a ton of PI Square posts about it, and here's the User Guide for Coresight Extensibility.
I've looked at using an Element Relative display but haven't gotten around to adding all the tags in the AF. thanks for the link to the Coresight Extensibility, I'll be sure to take a look.
Thanks again for your help,