8 Replies Latest reply on Jun 13, 2018 4:38 PM by RyanVal

    Would like to show notes on a PI tag selected in processbook

    RyanVal

      Our displays have lots of tags on them so having text boxes gets too messy, or having the text boxes at the bottom gets too lengthy. Having a button by each tag would be very tedious and the notes are too long to be put in as the PI tag description.

       

      Similarly to how right click >"Show details and annotations" > "statistics" changes and shows info for each tag slected, I'd like to show notes associated with a PI tag. Perhaps coming from an excel sheet like here:

      Processbook: Make a lookup in Excel

       

      Is it possible to have the notes show up on the display, a dock-able window or a floating window depending which PI tag is selected? How? Any help is appreciated

        • Re: Would like to show notes on a PI tag selected in processbook
          kduffy

          Hi Ryan,

           

          I'm not sure that there's an easy way to do this.

           

          The functionality you're describing is basically what the details and annotations pane is in terms of usability, but the exact data it's accessing is not what you want. Since you can't extend the details and annotations page to include this, then a new custom addin or VBA project will need to be written.

           

          If you wanted to go that route, one thing I think should work is to create a window in VBA and dock it using something like pbDockPosition, then you can use the Excel ODBC driver in conjunction with ODBC datasets that utilize placeholders. You can have a Display_SelectionChange event that'll trigger any time a new item is selected, and the code in that event handler can detect if you just clicked on a value symbol. If you did, it could set the odbc dataset placeholder to match name of the tag in the value symbol, then the result of that query can be displayed in the docked window.

           

          Alternatively, if you have AF then you could add your notes as attributes or child attributes, and put those into ProcessBook either directly or through element relative, etc. Either way, it would greatly simplify the approach and those notes would be exposed to any PI client or library if the AF server were the one querying teh Excel sheet, instead of it being locked into ProcessBook.

           

          What are your thoughts on these approaches?

           

          Kelsey

            • Re: Would like to show notes on a PI tag selected in processbook
              RyanVal

              Thank you for the reply! My site hasn't rolled out AF yet (and probably won't for a while) so I'll have to go the other route. Does the VBA code have to be written in each processbook graphic I'd want to use it in? I've done some work in VBA (excel) before but I'm not too familiar with pbDockPosition, ODBC datasets or Display_SelectionChange. I'll try searching and educating myself. If there's any good examples on these subjects please let me know.

                • Re: Would like to show notes on a PI tag selected in processbook
                  kduffy

                  If you wanted to go the VBA route, then you could save the bulk of the code as a module, and import it into each display. Then you'd need to recreate only the event handlers that call the functions in the module when you make subsequent displays (such as Display_open() to call a function in the module such as ShowNotesPane(); and then a Display_SelectionChange() handler that calls a function in the module such as UpdateSelection()).

                   

                  If you wanted to have everything work out of the box for all new displays created, then you would want to go down the custom add-in route. This can very easily become a substantial amount of development work, though, so I wouldn't necessarily recommend it. But if you are interested in that route, you can follow these templates, and you'll need to make a few other changes from there with the registration process that we can assist with if it gets that far. In this route, though, you'd be using Visual Studio and either C# or VB.NET instead of VBA within ProcessBook.

                   

                  As for examples, everything we have in documentation form will be in the programmers guides (2015 is the latest one, it's a chm format; 2009 is the latest one in pdf format). Within the pdf version, chapter 6 (starting on page 71) provides information about dockable windows in general and has numerous example code chunks throughout the chapter. I don't think we have an entirely start to finish example anywhere, maybe there's some on pisquare somewhere, but the guide walks you through the whole process, more or less, over the course of a few dozen pages.

                   

                  But like I said earlier, this effort, especially for someone who isn't already familiar with VBA, is probably going to be a large undertaking, so I would keep that in mind.

                   

                  Kelsey

                    • Re: Would like to show notes on a PI tag selected in processbook
                      RyanVal

                      Thanks! I lean towards going down the add-in route and taking on a big project for a cleaner result that can be re-used for new graphics as we create new ones all the time. The link "these templates" takes me to a page "file you selected is not available".

                      • Re: Would like to show notes on a PI tag selected in processbook
                        RyanVal

                        Kelsey,

                         

                        I'm just now getting back to this project. I'd like to go the vba/odbc route but I didn't get very far setting up the odbc following the link I posted in my original post.  So say I have an excel sheet with pi tags in column A and info to be displayed in column B of the spreadsheet. When I left click on a value in run mode on the processbook display I'd like the selected value's tag to be searched for in the excel sheet (column A) and have the info in column B displayed on the PB display. I get mixed up in the "query". Would appreciate help!

                          • Re: Would like to show notes on a PI tag selected in processbook
                            kduffy

                            Hi Ryan,

                             

                            I got everything working on my machine with the following steps:

                             

                            In Excel, I added some tag names in one column (with a header) and some values in the next one (also with a header). Then I highlighted the whole table and gave it the name of "tagValues"

                             

                            I saved this as an Excel 1997-2003 format (.xls) file just to be safe, then created the DSN in the ODBC Data Source administrator (32-bit) > System DSN by clicking Add > Microsoft Excel Driver (*.xls) > selecting the workbook that I had just created.

                             

                            Then in ProcessBook, I made the ODBC dataset from Tools > Datasets > New > ODBC

                             

                            I selected my Excel DSN from the Data Source drop down list, and for the query I put in:

                             

                            SELECT value FROM tagValues WHERE tag=?

                             

                            If you refer to the above screenshot from Excel:

                            "value" is the name of the second column

                            "tag" is the name of the first column

                            "tagValues" is the name of the table

                             

                            Then I clicked the Placeholders button, which is no longer greyed out since I have a "?" in my query, and I entered in the default value of "sinusoidu" for the placeholder that I named "tagName" and set to type of Text.

                             

                            Clicked ok and confirmed that the value was being read correctly:

                             

                            Then in VBA, I wrote a handler for the Display_SelectionChanged() event:

                            Private Sub Display_SelectionChange()
                            
                            Dim thisSym As Symbol
                            Dim longTagName As String
                            Dim splitTags As Variant
                            Dim shortTagName As String
                            Dim odbcDS As ODBCDataset
                            Dim dsName As String
                            Dim thesePHs As placeholders
                            Dim thisPH As Placeholder
                            
                            dsName = "EXCELDS"
                            
                            For Each thisSym In ThisDisplay.SelectedSymbols
                            
                                If thisSym.Type = 7 Then
                                    
                                    longTagName = thisSym.GetTagName(1)
                                    Debug.Print longTagName
                                    splitTags = Split(longTagName, "\")
                                    shortTagName = splitTags(3)
                                    Debug.Print shortTagName
                                    
                                    Set odbcDS = ThisDisplay.Datasets.GetDataset(dsName)
                                    Set thesePHs = odbcDS.placeholders
                                    Set thisPH = thesePHs.Item(1)
                                    Call thisPH.SetValue(shortTagName, pbPlaceholderText)
                                    
                                    Call ThisDisplay.Datasets.SetDataset(odbcDS)
                                                
                                End If
                            
                            Next thisSym
                            

                             

                            Now, when I click on one of the value symbols, it reads whether or not it's a value symbol, then if it is, it splits the tag name out of the full \\server\tagname string, and replaces the placeholder value with the new tag name.

                                    

                             

                            Kelsey

                            1 of 1 people found this helpful
                              • Re: Would like to show notes on a PI tag selected in processbook
                                RyanVal

                                This was SUPER helpful. I had a good chunk of it but just couldn't figure out changing the placeholder in VBA. Thank you so much!

                                 

                                ran into a couple problems:

                                1. There's a character limit of 255 for bringing in the value from excel. Is there a way around this? Could the values be dynamically brought into a text box instead of a data set?

                                 

                                2.If I open the referenced excel book first and then PI processbook they'll both open. However, if I have processbook open and then try to open excel it will only let me open a read only. Is there a way around this? Processbook will be open all the time with excel being opened periodically. Also if I have the excel book opened first if I save it then close it the value in pi no longer updates when other values are selected. Thoughts?