Loading Partial Element Hierarchy
- Last UpdatedNov 18, 2025
- 3 minute read
- PI System
- AF SDK 2024 R2
- Developer
In some cases, when loading an element hierarchy into the client, more control is needed over the individual objects of the hierarchy which need to be loaded than LoadElementsToDepth provides. This example uses the LoadElementReferences method to illustrate a mechanism for loading the child elements for multiple elements at one time.
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// Below is an alternate mechanism to load hierarchical elements 16// in bulk. The LoadElementReferences will load the next level 17// of a hierarchy from the list of elements provided it. 18// In this example, we load 4 levels of the hierarchy, but only 19// fully load and process the last level 20AFNamedCollectionList<AFElement> elementsLevel1 = 21 new AFNamedCollectionList<AFElement>(); 22elementsLevel1.Add(myNorthPlantArea56); 23 24AFNamedCollectionList<AFElement> elementsLevel2 = 25 AFElement.LoadElementReferences(elementsLevel1); 26 27AFNamedCollectionList<AFElement> elementsLevel3 = 28 AFElement.LoadElementReferences(elementsLevel2); 29 30AFNamedCollectionList<AFElement> elementsLevel4 = 31 AFElement.LoadElementReferences(elementsLevel3); 32 33AFElement.LoadElements(elementsLevel4); 34 35// Now process just this level 36int count = 0; 37foreach (AFElement item in elementsLevel4) 38 count += item.Attributes.Count; 39 40Console.WriteLine("Found {0} Elements at the 4th level which contain {1} Attributes.", 41 elementsLevel4.Count, count);
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' Below is an alternate mechanism to load hierarchical elements 19' in bulk. The LoadElementReferences will load the next level 20' of a hierarchy from the list of elements provided it. 21' In this example, we load 4 levels of the hierarchy, but only 22' fully load and process the last level 23Dim elementsLevel1 As New AFNamedCollectionList(Of AFElement)() 24elementsLevel1.Add(myNorthPlantArea56) 25 26Dim elementsLevel2 As AFNamedCollectionList(Of AFElement) = 27 AFElement.LoadElementReferences(elementsLevel1) 28 29Dim elementsLevel3 As AFNamedCollectionList(Of AFElement) = 30 AFElement.LoadElementReferences(elementsLevel2) 31 32Dim elementsLevel4 As AFNamedCollectionList(Of AFElement) = 33 AFElement.LoadElementReferences(elementsLevel3) 34 35AFElement.LoadElements(elementsLevel4) 36 37' Now process just this level 38Dim count As Integer = 0 39For Each item As AFElement In elementsLevel4 40 count += item.Attributes.Count 41Next 42 43Console.WriteLine("Found {0} Elements at the 4th level which contain {1} Attributes.", elementsLevel4.Count, count)
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.