ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.UtilityNetwork Namespace / UtilityNetwork Class / TraverseAssociations Method
The elements to begin the traversal.
The type of traversal to run.
Example

In This Topic
    TraverseAssociations Method
    In This Topic
    Provides a mechanism to return all TraverseAssociationsResult objects beginning at a list of starting elements and following a specified traversal.
    Syntax

    Parameters

    startElements
    The elements to begin the traversal.
    traverseAssociationsDescription
    The type of traversal to run.

    Return Value

    A single TraverseAssociationsResult containing the Associations and desired field values.
    Exceptions
    ExceptionDescription
    startElements is empty.
    startElements or traverseAssociationsDescription is null.
    ArcGIS Enterprise versions 10.8.1 or lower do not support the traverse associations operation.
    A geodatabase-related exception has occurred.
    Example
    Get traverse associations result from downward traversal
    {
      // This routine demonstrates how to get the associations involved in a downward traversal from a set of starting elements
      static void GetTraverseAssociationsResultFromDownwardTraversal(UtilityNetwork utilityNetwork, IReadOnlyList<Element> startingElements)
      {
        // Set downward traversal with maximum depth
        TraverseAssociationsDescription traverseAssociationsDescription =
          new TraverseAssociationsDescription(TraversalDirection.Descending);
    
        // Get traverse associations result from the staring element up to maximum depth
        TraverseAssociationsResult traverseAssociationsResult =
          utilityNetwork.TraverseAssociations(startingElements, traverseAssociationsDescription);
    
        // Get associations participated in traversal
        IReadOnlyList<Association> associations = traverseAssociationsResult.Associations;
      }
    }
    Get traverse associations result from upward traversal with depth limit
    {
      // This routine demonstrates how to get the associations involved in an upward traversal from a set of starting elements, up to a specified depth limit
      static void GetTraverseAssociationsResultFromUpwardTraversalWithDepthLimit(UtilityNetwork utilityNetwork, IReadOnlyList<Element> startingElements)
      {
        // List of fields whose values will be fetched as name-values pairs during association traversal operation
        List<string> additionalFieldsToFetch =
          new List<string> { "ObjectId", "AssetName", "AssetGroup", "AssetType" };
    
        // Set downward traversal with maximum depth level of 3
        TraverseAssociationsDescription traverseAssociationsDescription =
          new TraverseAssociationsDescription(TraversalDirection.Ascending, 3)
          {
            AdditionalFields = additionalFieldsToFetch
          };
    
        // Get traverse associations result from the staring element up to depth level 3
        TraverseAssociationsResult traverseAssociationsResult =
          utilityNetwork.TraverseAssociations(startingElements, traverseAssociationsDescription);
    
        // List of associations participated in traversal
        IReadOnlyList<Association> associations = traverseAssociationsResult.Associations;
    
        // KeyValue mapping between involved elements and their field name-values
        IReadOnlyDictionary<Element, IReadOnlyList<FieldValue>> associationElementValuePairs =
          traverseAssociationsResult.AdditionalFieldValues;
    
        foreach (KeyValuePair<Element, IReadOnlyList<FieldValue>> keyValuePair in associationElementValuePairs)
        {
          // Element
          Element element = keyValuePair.Key;
    
          // List of field names and their values
          IReadOnlyList<FieldValue> elementFieldValues = keyValuePair.Value;
        }
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also