3 Replies Latest reply on Apr 6, 2016 3:45 PM by gregor

    ProcessBook dataset name read only?

    Asle Frantzen

      I'm creating a display with some VBA code to import all datasets stored in all open PB displays.

       

      I want to handle if any of the displays have datasets with the same name as any of the already imported datasets in my display, and rename the dataset if so. It's better to get everything, and then the user can review the imported datasets after.

       

      I'm "For Each"-ing my way through all open displays, and all datsets, copying the datasets using the dataset.Copy(ThisDisplay) method. The problem is this method only copies datasets from one display to another, and returns an error if there's already a dataset defined with that name. My idea was to append a postfix to the name in the source display before using this method, but that doesn't seem to work. The "PI ProcessBook Programmer Reference Guide" help file says the Dataset Name Property is read/write, but when I try to rename a dataset in the source display before copying it I get an error message saying the "Dataset name is read only". I didn't test renaming a dataset in the same display as my VBA code run in, possibly I can only rename local datasets.

       

      Any suggestions on how to finish this? Any way to copy a dataset into a local variable, and the create it in my display? (Datasets.GetDataset("Name") only seems to return a pointer to the dataset)

       

      Of course I could just skip any datasets with matching names, but that's not very user friendly.

        • Re: ProcessBook dataset name read only?
          gregor

          Hello Asle,

           

          let me open a Technical Support case for you on this obvious bug even I am not yet sure if the bug sits in the documentation or the implementation. The typo inside the error is another - even minor bug.

           

            • Re: ProcessBook dataset name read only?
              Asle Frantzen

              All right, I've solved my issue with another approach than described above.

               

              Gregor confirmed that it was, in fact, the documentation which was wrong. We are not allowed to change the name of a dataset, so that means I'd have to have a backup approach if I detect a local dataset with the same name as the one I want to copy.

               

              I had tested a few things in my code before I squared my way into this thread: https://pisquare.osisoft.com/thread/7767

              Daniel Takara's example code was confirmed to work, so I decided to snip the most important parts - and integrate it with my code. I had a "myDataset.Expression = remoteDataset.Expression" statement, and it failed at that line. Since the VBA debugger is pretty stupid/uninformative I assumed I couldn't access the expression field of the remote dataset, but eventually I discovered I had dimensioned myDataset as Dataset instead of PIExpressionDataset. So the problem was actually on the left side of the assignment - myDataset didn't have a property called Expression. Once I changed it to be dimensioned as a PIExpressionDataset it worked like a charm.

               

              So now I create a new dataset with a unique postfix appended to the name, then retrieve it, and set all the properties to match the properties of the remote dataset.

                • Re: ProcessBook dataset name read only?
                  gregor

                  Hi Asle,

                   

                  Thank you for finalizing your question with the result of our investigation. The reasoning for not allowing to change a Dataset's name is that it would require to iterate through all Symbols to see if the Dataset is referenced there and to change the reference to avoid leaving the user with abandoned references.