ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Data.NetworkDiagrams Namespace / NetworkDiagram Class
Members Example

In This Topic
    NetworkDiagram Class
    In This Topic
    Represents a network diagram.
    Object Model
    NetworkDiagram ClassDiagramManager ClassDiagramTemplate ClassNetworkDiagramInfo ClassDiagramElementsAttributes ClassDiagramElementQueryResult Class
    Syntax
    public sealed class NetworkDiagram : ArcGIS.Core.CoreObjectsBase, System.IDisposable  
    Public NotInheritable Class NetworkDiagram 
       Inherits ArcGIS.Core.CoreObjectsBase
       Implements System.IDisposable 
    Remarks
    New network diagrams can be created using the DiagramManager.CreateNetworkDiagram factory method. Existing network diagrams can be retrieved from the DiagramManager or DiagramTemplate classes.
    Example
    Get Network Diagrams
    using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
    {
      // get all the diagrams
      IReadOnlyList<NetworkDiagram> diagrams = diagramManager.GetNetworkDiagrams();
    
      // get a diagram by name
      NetworkDiagram diagram = diagramManager.GetNetworkDiagram(diagrameName);
    
      // get diagrams by extent
      diagrams = diagramManager.GetNetworkDiagrams(extentOfInterest);
    
      // get diagrams from a set of utility network feature GlobalIDs
      diagrams = diagramManager.GetNetworkDiagrams(globalIDs);
    
      // get diagrams from a set of utility network feature GlobalIDs within an extent
      diagrams = diagramManager.GetNetworkDiagrams(extentOfInterest, globalIDs);
    }
    Get a list of Network Diagrams with inconsistent ConsistencyState
    public List<NetworkDiagram> GetInconsistentDiagrams(UtilityNetwork utilityNetwork)
    {
      // Get the DiagramManager from the utility network
    
      using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
      {
        List<NetworkDiagram> myList = new List<NetworkDiagram>();
    
        // Loop through the network diagrams in the diagram manager
    
        foreach (NetworkDiagram diagram in diagramManager.GetNetworkDiagrams())
        {
          NetworkDiagramInfo diagramInfo = diagram.GetDiagramInfo();
    
          // If the diagram is not a system diagram and is in an inconsistent state, add it to our list
    
          if (!diagramInfo.IsSystem && diagram.GetConsistencyState() != NetworkDiagramConsistencyState.DiagramIsConsistent)
          {
            myList.Add(diagram);
          }
          else
          {
            diagram.Dispose(); // If we are not returning it we need to Dispose it
          }
        }
    
        return myList;
      }
    }
    Open a diagram pane from a Network Diagram
    // Create a diagram layer from a NetworkDiagram (myDiagram)
    DiagramLayer diagramLayer = await QueuedTask.Run<DiagramLayer>(() =>
    {
      // Create the diagram map
      var newMap = MapFactory.Instance.CreateMap(myDiagram.Name, ArcGIS.Core.CIM.MapType.NetworkDiagram, MapViewingMode.Map);
      if (newMap == null)
        return null;
    
      // Open the diagram map
      var mapPane = ArcGIS.Desktop.Core.ProApp.Panes.CreateMapPaneAsync(newMap, MapViewingMode.Map);
      if (mapPane == null)
        return null;
    
      //Add the diagram to the map
      return newMap.AddDiagramLayer(myDiagram);
    });
    
    Get Diagram from DiagramLayer
    public void GetDiagram(DiagramLayer diagramLayer)
    {
      // note - methods need to run on MCT
    
      NetworkDiagram diagram = diagramLayer.GetNetworkDiagram();
    
      // get the consistency state from the layer
      DiagramLayerConsistencyState dlState = diagramLayer.ConsistencyState;
    
      // or from the diagram
      NetworkDiagramConsistencyState ndState = diagram.GetConsistencyState();
    }
    Create a Network Diagram
    public void CreateNetworkDiagram(UtilityNetwork utilityNetwork, IEnumerable<Guid> globalIDs)
    {
      using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
      {
        // get the template
        DiagramTemplate template = diagramManager.GetDiagramTemplate(templateName);
    
        // create the diagram
        NetworkDiagram diagram = diagramManager.CreateNetworkDiagram(template, globalIDs);
      }
    }
    Get Network Diagram Information as JSON string
    public void GetDiagramContent(UtilityNetwork utilityNetwork)
    {
      using (DiagramManager diagramManager = utilityNetwork.GetDiagramManager())
      {
        // get a diagram by name
        NetworkDiagram diagram = diagramManager.GetNetworkDiagram(templateName);
    
        string json_content = diagram.GetContent(true, true, true, true);
      }
    }
    
    Change the Layout of a Network Diagram
    public void DiagramElementQueryResultAndNetworkDiagramSubsetClasses(Geodatabase geodatabase, DiagramManager diagramManager, string diagramName)
    {
      // Retrieve a diagram
      using (NetworkDiagram diagramTest = diagramManager.GetNetworkDiagram(diagramName))
      {
        // Create a DiagramElementQueryByElementTypes query object to get the diagram elements we want to work with
        DiagramElementQueryByElementTypes query = new DiagramElementQueryByElementTypes();
        query.QueryDiagramJunctionElement = true;
        query.QueryDiagramEdgeElement = true;
        query.QueryDiagramContainerElement = true;
    
        // Retrieve those diagram elements
        DiagramElementQueryResult elements = diagramTest.QueryDiagramElements(query);
    
        // Create a NetworkDiagramSubset object to edit this set of diagram elements
        NetworkDiagramSubset subset = new NetworkDiagramSubset();
        subset.DiagramJunctionElements = elements.DiagramJunctionElements;
        subset.DiagramEdgeElements = elements.DiagramEdgeElements;
        subset.DiagramContainerElements = elements.DiagramContainerElements;
    
        // Edit the shapes of the diagram elements - left as an exercise for the student
        TranslateDiagramElements(subset);
    
        // Save the new layout of the diagram elements
        diagramTest.SaveLayout(subset, true);
      }
    }
    Inheritance Hierarchy

    System.Object
       ArcGIS.Core.CoreObjectsBase
          ArcGIS.Core.Data.NetworkDiagrams.NetworkDiagram

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also