7 Replies Latest reply on Jun 3, 2014 9:16 AM by Rhys Kirk

    AF element create in BULK




      Can anyone advise me how to create bulk elements and update its attribute using AF-SDK.


      I don't want to use AF builder. 


      I have about 10000 elements and each element have 50 attribute.


      I have a flat file which has information about the element and thier attribute. I need to read the flat file .csv and create elements and update their attribute. Is there anything available ready through with i can update the AF database easily and performance is also good

        • Re: AF element create in BULK

          You can use the AF Import utility - it can read an XML file.   (C:\Program Files\PIPC\AF\AFImport.exe)


          What's the reason for not wanting to use the AF Builder?

            • Re: AF element create in BULK
              Marcos Vainer Loeff

              Hello Viju,


              It will probably require less effort to use PI AF Builder than developing a custom console application or PowerShell script, especially if you want to perform this job only once.


              But if you still want to use PI AF SDK, please use element templates in order to speed up the elements creation process. Is it possible to do so? Are the 50 attribute names the same for all 10k elements? If so, it will make your job really easy, because you will create the element template with the attributes template only once and then use only one call to create a new element.


              And finally, I wouldn’t care too much with the performance in your case because you are running this code only once. It is a different scenario compared to when you are developing an application that keeps running and making calculations.


              Hope it helps!

                • Re: AF element create in BULK

                  Thanks Marcos. Yes I plan to create a Template and use AF-SDK.


                  Can you please guide me with the AF -SDK code.


                  My flat file will look something like this below.


                  Asset id with Description will be the root element. and others will be attribute.


                  There are chances that their can be parent -child relationship as well. How to handle that?


                  Asset     Description     Location     Parent     Rotating Item     Site     Asset Type     Sub Class


                  1103057003     VENT MIV AT CMN I/L HDR OF ACW PUMPS     S1U01-1ACW-1TUA-1PAC-1PACCO               PD11     VALVE     


                  1103057001     ISLN MIV AT CMN I/L HDR OF ACW PUMPS     S1U01-1ACW-1TUA-1PAC-1PACCO               PD11     VALVE     


                  1103030001     STRAINER AT CMN I/L HDR OF ACW PUMPS     S1U01-1ACW-1TUA-1PAC-1PACCO               PD11     FILTER     

                    • Re: AF element create in BULK

                      Hi Viju,


                      PI Builder (the new name for AF Builder) will be the easiest way. This can handle templates and the parent/child relationships.


                      AF has a number of reference types for hierarchies, you will need to decide which is best for your application; I'm guessing Parent-Child is probably what you are looking for.


                      If you do go down the custom code route (still recommend PI Builder) then I would suggest starting with the AF SDK documentation which is part of the developer tools under downloads. There are a number of good video's on the auditorium that will also help. Lastly there is a white paper on the library regarding creating templates from a CSV file; this paper is fairly old but the basics are the same and it can be easily adapted to creating templates.


                      The only advice for the parent/child relationships is make sure the parent is created first. Obvious I know

                        • Re: AF element create in BULK

                          Hi everybody !


                          I'm glad I've found this discussion since my team and I have roughly the same goal than Viju except that we have about 1,200,000 AFElement to create. Using PI Builder to build this structure seems therefore unthinkable...


                          We looked up in AFSDK help files but we can't find a way to add elements in bulk. We did wrote some code in C#, however we are not convinced by the performances we got... Has someone already encountered a similar case ? Is there best practices to follow to ensure good performances during AFElement creation with AFSDK ? By the way, we are using AFSDK 2.6.


                          Thanks !

                            • Re: AF element create in BULK
                              David Hearn

                              To add elements in bulk with the AFSDK all you need to do is create the elements by adding them to the desired Elements collection and then doing an AFDatabase.Checkin. You will probably want to do this in blocks of elements and not attempt to create them all with a single CheckIn.

                                • Re: AF element create in BULK
                                  Rhys Kirk

                                  You're not going to be creating millions of Elements on a frequent basis though, right? You should allow for some performance degradation during one-off large imports of a hierarchy. If you're doing this regularly then it would probably be useful to understand why you do it so often.