Out of curiosity, what version of ProcessBook are you using? Do I understand the available modules tab to mean a Module Relative display (as in PI Module Database)?
I'm using version 18.104.22.168. I'm not too sure if the available modules tab is a Module Relative display.
OK, so definitely Module Database modules in this particular window. Typically this add-in is used to provide context to dynamic symbols such as Trends, Values, etc, when they are associated with the PI Module Database. This is the classic Module Relative Display functionality. Selecting a different module in the list would provide a new data context to said dynamic symbols. If you want to use this window as a means of display navigation, you will need to write some VBA code behind your display to capture the context change, and perform some action based on that change, in this case opening a pre-defined PDI file. Having said all this, I've programmatically used the newer Element Relative Display context handler in code to perform some custom actions, but not this particular handler. I'm pretty sure what you want to do can be done, and I will need to dig out my code from the project I did with the ERD and see if it can be adapted.
I assume that you have a string property defined in your Modules that contains the path of the PDI file you want to open when a specific module is clicked? If not, I would suggest that you will need to add such a property so that your custom code will know what file is to be opened.
I'll get back to you later today once I've had a chance to dig out and modify some code to see how much of this is actually possible.
So I've had a look through one of my older projects, and found some code that does some similar things. Firstly, you will need to declare a ContextHandler variable with events:
Dim WithEvents ctx As ContextHandler
In your Display_Open() event handler, you will need to set a reference to the context:
Set ctx = Application.ContextHandlers.Item("ModuleContext")
You will need to generate the event handler stub for the ContextChanged event:
Private Sub ctx_ContextChanged(FromDisplay As Display, FromContextHandler As ContextHandler)
Within this event handler, get a handle to the actual context that has been selected:
Dim selectedcontext As String
selectedcontext = ctx.CurrentContext(FromDisplay)
As I don't currently have a PI Server with an accessible PI Module Database, I haven't been able to test what the string format is of the returned context. In any event, you should have a PI Module name that you can work with. From here, you will need some PI-SDK code to get a handle to the PIModule object represented by the context. Once you have this, you can read the PIProperty object that contains the file path to the PDI file you want to open, and then open this file as follows:
Application.Displays.Open "C:\PathToYourFile\TargetFile.pdi", True
It should go without saying at this point that you will also need to include PI-SDK in your project to handle the connection to the PI server, and to reference the PI Module Database.
If I can spin up an older version of PI a little later to test against, I will try and post a more complete code sample.
2 of 2 people found this helpful
So here is a very simple, but useable code sample:
Option Explicit Dim WithEvents ctx As ContextHandler Dim server As PISDK.server Dim mdb As PIModuleDB Private Sub ctx_ContextChanged(FromDisplay As Display, FromContextHandler As ContextHandler) Dim module_path() As String Dim mod_name As String Dim module As PIModule module_path = Split(ctx.CurrentContext(FromDisplay), "\") mod_name = module_path(UBound(module_path)) Set module = mdb.PIModules(mod_name) Application.Displays.Open module.PIProperties("FileName").Value, True End Sub Private Sub Display_Open() Set ctx = Application.ContextHandlers.Item("ModuleContext") Set server = PISDK.Servers.DefaultServer Set mdb = server.PIModuleDB End Sub
Hope this helps.
Just tested out the implementation and it works perfectly! Thank you for your help!