6 Replies Latest reply on Jan 10, 2017 7:31 PM by MikeSpath

    Using AFSDK to setup Analysis Template



      I'm desperately trying to understand how to work with Notifications via the AFSDK. I have attached two screen shots, one that shows the setup I have done through PI Explorer and the section of exported xml for the element template. I see in the XML that there are GUIDs created, is this because I'm using the built in limits (Traits?). When attempting this in code I'm completely lost on how to set that up. I've seen example code

      on configuring Event Frame and analytics::

        Creating Asset-Based Analytics Programmatically (Rollup and Event Frame Generation)

      but I'm still at a loss on how to code this. I need to be able to create the same element templates as well as event frame templates using the AFSDK and then create elements using the templates, all in the SDK, with no interface to PI explorer




        • Re: Using AFSDK to setup Analysis Template

          It might be helpful to take a look at the AF SDK Library Reference. It contain examples and the hierarchy of the AF SDK.


          Could you show us what you have? we might be able to discuss a solution.



          1 of 1 people found this helpful
            • Re: Using AFSDK to setup Analysis Template

              Hello Folks:

              Thank you for your guidance, I have been able to develop a little method that I can modularize to create my element templates (code below)

              I need to create an attribute on the same template that is not a pipoint reference but a formula reference. It takes the attribute that has the pipoint reference and uses the rounding formula : A=DO;[roundfrac(A,3)]

              How do I do that in code? I have been looking in the SDK help file but  AddFormula is only associated with UOM




                              // Create an Element Template

                              string strTemplateName = "DataSourceTemplate";

                              var ETExits = db.ElementTemplates[strTemplateName]; // check to see if it exists

                              if (ETExits == null)


                                  AFElementTemplate myElemTemplate = db.ElementTemplates.Add(strTemplateName);

                                  myElemTemplate.Description = "Template used to create my elements";



                                  //This code creates Attribute Template.

                                  AFAttributeTemplate Myattributetemplate = myElemTemplate.AttributeTemplates.Add("DO");

                                  Myattributetemplate.DefaultUOM = MyPISystem.UOMDatabase.UOMs["Percent"];

                                  Myattributetemplate.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(MyPISystem);

                                  Myattributetemplate.ConfigString = @"\\%Server%\%Element%.%Attribute%";



                                  // setup limits for DO

                                  AddLimitToAttribute(myElemTemplate, Myattributetemplate, 99.54, LimitType.HIHI);

                                  AddLimitToAttribute(myElemTemplate, Myattributetemplate, 77.324, LimitType.HI);

                                  AddLimitToAttribute(myElemTemplate, Myattributetemplate, 24.857, LimitType.LO);

                                  AddLimitToAttribute(myElemTemplate, Myattributetemplate, 0.5, LimitType.LOLO);

                                  AddLimitToAttribute(myElemTemplate, Myattributetemplate, 100, LimitType.Maximum);

                                  AddLimitToAttribute(myElemTemplate, Myattributetemplate, 0, LimitType.Minimun);

                                  AddLimitToAttribute(myElemTemplate, Myattributetemplate, 54, LimitType.Target);








                                  MessageBox.Show("must be new template");



                          catch(Exception ex)




                • Re: Using AFSDK to setup Analysis Template

                  You can give that a try if you want to create an attribute with a formula reference.


                                 PISystems myPISystems = new PISystems();

                                  //Connect to the AF Server

                                  PISystem myPISystem = myPISystems["MyAFSERVER"];


                                  //Connect to the AF Database

                                  AFDatabase myDb = myPISystem.Databases["MyAFDatabase"];


                                  //Create an Element

                                  AFElement myElement = myDb.Elements.Add("MyElement");


                                  //Create an Attribute

                                  AFAttribute myAttribute = myElement.Attributes.Add("MyAttribute");


                                  AFPlugIn formula = myPISystem.DataReferencePlugIns["Formula"];

                                  myAttribute.DataReferencePlugIn = formula;

                                  myAttribute.ConfigString = "A=a2;[A*2]";




              • Re: Using AFSDK to setup Analysis Template

                Hi Mike,


                I suggest you try to take a look at Mike Zboray Blog: Here he explains it in a detail and should contain what you need. Please note the version as well.

                Configure a Notification via AF SDK




                1 of 1 people found this helpful
                • Re: Using AFSDK to setup Analysis Template
                  Mike Zboray

                  The Guids are the attribute template ids. They are not strictly necessary, but can assist in cases where a user renames the attribute templates later with breaking anything. The xml has many characters escaped but you can basically take the config string with the ids removed if you want to reuse it in another template.

                  1 of 1 people found this helpful