4 Replies Latest reply on Dec 4, 2014 3:34 AM by Doddabasappa

    Create Element at specific path






      I want to create Element using template by passing path.


      For example:












      Now I want to create Element 'Child3' by passing path.




      How can I do that?











        • Re: Create Element at specific path
          Marcos Vainer Loeff



          I have not tested the code snippet below but it should work. Don't forget to check in!



                      AFDatabase myDb = new PISystems()["AFSERVERNAME"].Databases["DatabaseName"];
                      AFElement myElement = myDb.Elements["ParentName"];
                      AFElementTemplate myElementTemplate = myDb.ElementTemplates["myTemplateName"];
                      myElement.Elements.Add(newElementName, myElementTemplate);





          Hopefully, this is what you are looking for!

          • Re: Create Element at specific path

            Hello Doddabasappa,


            Have you looked into the option using AF Builder plug-in to Microsoft Excel? The plug-in ships together with the AF Client installation.


            If you prefer building your own application, I suggest watching the training video Basics of AF Programming Part 1 available at the Training Center together with more useful training resources. Please also have a look into the Tutorial - Create AF Element Templates from a CSV File available at the Library. Last but not least, please download and install PI AF Developer Tools_2014 R2 from the Download Center, category "PI Asset Framework". After installing this package you will find AF SDK Reference (AFSDK.chm) at %PIHOME%\Help\ with some code examples in VB.Nat and C#

              • Re: Create Element at specific path
                Dan Fishman

                In addition to what Gregor and Marcos provide you can always use the FindObject method and provide a path.


                 For example, I want to add a tank to Division 1 and my AF Database has top level element "My Plant" followed by a list of divisions.  I first obtain the Division 1 element and then I can add a new element to it.

                  AFElement myElement = AFObject.FindObject(@"\\AFServerName\AFDatabaseName\My plant\Division 1") as AFElement;

                 Also, if you need to find multiple elements the AFElement class has a FindElementsbyPath method.