Loading Element Hierarchy
- Last UpdatedNov 18, 2025
- 3 minute read
- PI System
- AF SDK 2024 R2
- Developer
Because elements are organized into a hierarchy, there are frequently situations where an application is going to want an entire hierarchy loaded into the client memory space. This example uses the LoadElementsToDepth method to illustrate a mechanism for bulk loading an entire hierarchy of elements into the client.
1// Get the Database 2PISystems myPISystems = new PISystems(); 3PISystem myPISystem = myPISystems.DefaultPISystem; 4if (myPISystem == null) 5 throw new InvalidOperationException("Default PISystem was not found."); 6AFDatabase myDB = myPISystem.Databases[dbName]; 7if (myDB == null) 8 throw new InvalidOperationException("Database was not found."); 9 10// Get a specific area of the element hierarchy to load 11AFElement myNorthPlantArea56 = myDB.Elements[@"NorthPlant\Area56"]; 12if (myNorthPlantArea56 == null) 13 throw new InvalidOperationException(@"Element 'NorthPlant\Area56' was not found."); 14 15// Use AFElement.LoadToDepth to fully load this part of the hierarchy. 16// This will utilize fewer RPC's than navigating through the hierarchy 17// one element at a time. Note that care needs to be taken to not attempt 18// to load too many objects into memory at once. Here, we limit the load 19// to 3 additional levels of the hierarchy, not to exceed 1000 total elements. 20AFNamedCollectionList<AFElement> allElements = AFElement.LoadElementsToDepth( 21 myNorthPlantArea56.Elements, true, 3, 1000); 22 23// Once the elements are loaded, we can process them as usual. In the example 24// below, we have written a recursive routine which counts the bad data for the 25// entire element hierarchy. 26int badDataCount = CountBadData(myNorthPlantArea56, 4); 27 28Console.WriteLine("Found {0} Elements which contain {1} Attributes with bad data.", 29 allElements.Count, badDataCount); 30 31// Prevent garbage collection by the .NET CLR until this point. 32GC.KeepAlive(allElements);
1' Get the Database 2Dim myPISystems As New PISystems() 3Dim myPISystem As PISystem = myPISystems.DefaultPISystem 4If myPISystem Is Nothing Then 5 Throw New InvalidOperationException("Default PISystem was not found.") 6End If 7Dim myDB As AFDatabase = myPISystem.Databases(dbName) 8If myDB Is Nothing Then 9 Throw New InvalidOperationException("Database was not found.") 10End If 11 12' Get a specific area of the element hierarchy to load 13Dim myNorthPlantArea56 As AFElement = myDB.Elements("NorthPlant\Area56") 14If myNorthPlantArea56 Is Nothing Then 15 Throw New InvalidOperationException("Element 'NorthPlant\Area56' was not found.") 16End If 17 18' Use AFElement.LoadToDepth to fully load this part of the hierarchy. 19' This will utilize fewer RPC's than navigating through the hierarchy 20' one element at a time. Note that care needs to be taken to not attempt 21' to load too many objects into memory at once. Here, we limit the load 22' to 3 additional levels of the hierarchy, not to exceed 1000 total elements. 23Dim allElements As AFNamedCollectionList(Of AFElement) = AFElement.LoadElementsToDepth(myNorthPlantArea56.Elements, True, 3, 1000) 24 25' Once the elements are loaded, we can process them as usual. In the example 26' below, we have written a recursive routine which counts the bad data for the 27' entire element hierarchy. 28Dim badDataCount As Integer = CountBadData(myNorthPlantArea56, 4) 29 30Console.WriteLine("Found {0} Elements which contain {1} Attributes with bad data.", allElements.Count, badDataCount) 31 32' Prevent garbage collection by the .NET CLR until this point. 33GC.KeepAlive(allElements)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.