4 Replies Latest reply on Nov 2, 2016 3:59 PM by hgodin

    Applying tag configuration scripts in a template using AF SDK

    natdavidson

      Hi, another AF SDK question,

      I have elements built with the right hierarchy, with templates applied for each element, using AF SDK. These templates define attributes which are mostly tag references, but the tag attributes are put together using the tag configuration script in PSE.

       

      How could I apply these tag configs, and build the tags through AF SDK?

       

      Also, how would I reset an element and it's attributes to template?

        • Re: Applying tag configuration scripts in a template using AF SDK
          Roger Palmen

          Not sure if i understand the issue. If you have tag creation attributes in your template, the instantiation of the template in an element will ensure the tag attributes are generated. Only thing you need is to create or update PI Points: Reset attribute to template and create the PI point

           

          Reset to template: PI AF - Reset to Template in Bulk

            • Re: Applying tag configuration scripts in a template using AF SDK
              natdavidson

              Ya, sorry, I should have been more straigh forward. I want to do the same function as "Create or Update Data Reference" in PSE. I've done some looking around and come up with this:

                                      AFElement parentElement = AFObject.FindObject(pathDefault) as AFElement;

                                      AFElement myElement = parentElement.Elements.Add("My Element Name", myElementTemplate);

               

                                      parentElement.Database.CheckIn(AFCheckedOutMode.ObjectsCheckedOutThisSession);

               

               

                                      foreach (AFAttribute CurAttribute in myElement.Attributes)

                                      {

                                          CurAttribute.DataReference.CreateConfig();

                                      }

              But when i run this, i get an error, more of a c# error I believe,

               

                  " An unhandled exception of type 'System.NullReferenceException' occurred in AFIntegratorAndSNMP.exe

                    Additional information: Object reference not set to an instance of an object."

               

              Any help with this error would be appreciated.

                • Re: Applying tag configuration scripts in a template using AF SDK
                  natdavidson

                  For anyone in the future that runs into something like this, where it looks like some code should be working but it's not, one thing to check would be to make sure that the "Optimize Code" checkbox is unchecked under project properties. For some reason, VS 2015 was removing a variable or deactivating it, or something, and unchecking this option fixed this error for me, and attributes were successfully built.

                   

                  Not sure if I should link to other pages from here, but I found my answer here.

                   

                  Thanks for your help as well Roger Palmen.

                  1 of 1 people found this helpful
              • Re: Applying tag configuration scripts in a template using AF SDK
                hgodin

                Hi Nate,

                 

                Glad you found the answer to your question and thanks for sharing the link that helped you to resolve it!

                Do you have any more questions on this topic?