6 Replies Latest reply on Aug 23, 2018 2:13 PM by volljm

    Update PI Points via AF

    volljm

      Is there an ability to "Create / Update PI Points" for existing AF Elements in some automated fashion (on a schedule for example)?

       

      AFImport.exe could be scheduled but it only updates PI Points on NEW elements, not existing elements

      PIBuilder can update PI Points while importing the AF elements, but its commands are not accessible through VBA, thus its a manual process

      System Explorer can update PI Points, but again its a manual process.

       

      I suspect there is an AF SDK method to do this . . . but the preference would be not have to go to the lengths of utilizing Visual Studio to create an application.

        • Re: Update PI Points via AF
          John Messinger

          Hi James,

           

          The AFSDK provides a method to do just this - AFDataReference.CreateConfig. If you don't want to create a compiled application to do this, remember that assemblies such as the AFSDK can be used in PowerShell. This may be a viable option for you, as you can create a PowerShell script that will allow you to call the required AFSDK methods you need for this task, and you can easily automate this using the built-in Windows Task Scheduler. There are a number of forum posts as well as some blog posts on using the AFSDK within PowerShell if you need help getting started down this path. A good introductory post I can recommend is Powershell and AFSDK example

           

          Cheers,

          John

            • Re: Update PI Points via AF
              volljm

              I've been able to figure out a bit of usage of AFSDK within Powershell; query elements, create elements on templates, etc. I have no been able to figure out how to call the createconfig() function with any of the optional arguments specified. If I try to specify arguments I get a "cannot find an overload...". Calling the createconfig() without arguments doesn't appear to do anything. If the PI Tag doesn't already exist i get a exception ("[-12001] Name Not Found in PInt") . . . If the tag does already exist I don't get an error, but the tag's configuration was not updated either.

               

              $AFSDKAssembly = [Reflection.Assembly]::LoadWithPartialName("OSIsoft.AFSDK") 

               

              $afServer = $afServers["PIAF Server"]

              $DB = $afServer.Databases["AF Database"] 

              $Element = $DB.Elements["Test Element"].elements["test child element"]

              $attribute=$element.Attributes["test attribute"]

              $attribute.DataReference.CreateConfig()

                • Re: Update PI Points via AF
                  John Messinger

                  Hi James,

                   

                  Your usage of the CreateConfig() method is correct, and this is exactly how I use it. I tend to use the ResetToTemplate method just immediately to ensure that the config I'm building is based on the current template settings. Following is a snippet from one of my PowerShell scripts I use for this task:

                   

                  foreach($attribute in $afElement.Attributes)
                  {
                       if (($attribute.DataReference -ne $null) -and ($attribute.DataReferencePlugIn.Name.Equals("PI Point"))
                       {
                            $attribute.Attributes["TagName"].ResetToTemplate();
                            $attribute.ResetToTemplate();
                            $attribute.DataReference.CreateConfig();
                       }
                  }
                  $afElement.CheckIn();
                  

                   

                  Does the resolved tag name from your Attribute Template meet the PI tag name rules (no disallowed characters)? I am assuming that the template is configured to allow point creation? Can you also confirm that your script process is authenticated to the Data Archive with sufficient permissions to create points?

                  • Re: Update PI Points via AF
                    volljm

                    to followup . . . i found it to be far simpler to just utilize a BAT file and Task Scheduler to call upon AFImport.exe and AFUpdatePluginConfiguration.exe

                     

                    • afimport.exe (root path) /file:(xml file path) /continueonerror:yes
                    • afupdatepluginconfigurations.exe "-root:(rootpath)" -createconfig

                     

                    I am comfortable with not resetting to template for this application since its design is to allow individual elements to deviate from the template to a certain degree after its initial creation.

                     

                    I haven't finished up this project (got side tracked on other stuff), so i would love to hear your thoughts, if you have some, on why this is not an appropriate approach

                • Re: Update PI Points via AF
                  sraposo

                  Hi James,

                   

                  Out of curiosity, can you explain a little more what your use case is? Why do you need to create PI Points linked to existing AF Attributes programmatically?

                   

                  I agree with John, if you don't want to develop a custom application, your next best option is PowerShell.

                   

                  Seb

                    • Re: Update PI Points via AF
                      volljm

                      We have external databases/data sources in which additional items (tags) are added, or existing items modified (description change for example). We have need for an easy way to keep the PI tags up to date with these items in the  external data source as well as creating additional tags automatically. AF is a logical place to hold much of this information, utilizing templates to drive consistent PI tag properties for particular data sources as well as a place to manage changes to these tag properties either individually or on the template level.

                       

                      Our preference is to utilize 'out of the box' components needing only some configuration (like AF) . . . keeping anything custom (code, applications, etc) to a minimum since these types of items become a maintenance issue long term since the skill set of having sufficient PI awareness AND ability to code an application is not widespread. I try to keep items like VBA or BAT files to a minimum, a couple lines at most and only if no other alternative is available.

                       

                      I have been meaning to explore PowerShell more and I suppose I didn't fully realize that the AF SDK components were available in that environment (you don't know what you don't know). I'll look more into that more. Thanks!