Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

Loading Partial Element Hierarchy

  • Last UpdatedJan 12, 2026
  • 2 minute read
Loading Partial Element Hierarchy

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);

See Also

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in