select the traced elements

02-06-2015 12:18 AM
New Contributor

I am developing a Add-ins button that do a upstream trace in a network , it works correctly without any error but it does not highlight the traced elements.

I do not know how to highlight the traced elements? thanks in advance

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

using ESRI.ArcGIS.esriSystem;

using ESRI.ArcGIS.Carto;

using ESRI.ArcGIS.Editor;

using ESRI.ArcGIS.EditorExt;

using ESRI.ArcGIS.Geodatabase;

using ESRI.ArcGIS.Geometry;

using System.Windows.Forms;

using ESRI.ArcGIS.NetworkAnalysis;

namespace testNet


    public class testNet : ESRI.ArcGIS.Desktop.AddIns.Button


        private IUtilityNetworkAnalysisExt m_utilNetExt;         

        public testNet()


            UID uidUtilNet = new UIDClass();

            uidUtilNet.Value = "esriEditorExt.UtilityNetworkAnalysisExt";

            m_utilNetExt = ArcMap.Application.FindExtensionByCLSID(uidUtilNet) as IUtilityNetworkAnalysisExt;



        protected override void OnClick()





            INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt;

                 ITraceTasks pTraceTasks = nax as  ITraceTasks;

                 INetwork net = nax.CurrentNetwork.Network;                


                 ITraceFlowSolverGEN tfs = new TraceFlowSolverClass() as ITraceFlowSolverGEN;

                 INetSolver netSolver = tfs as INetSolver;

                 netSolver.SourceNetwork = net;

                 INetworkAnalysisExtBarriers naxBarriers = m_utilNetExt as INetworkAnalysisExtBarriers;

                 INetElementBarriers juncElemBarriers, edgeElemBarriers;

                 naxBarriers.CreateElementBarriers(out juncElemBarriers, out edgeElemBarriers);

                 ISelectionSetBarriers selSetBarriers;

                 naxBarriers.CreateSelectionBarriers(out selSetBarriers);

                 netSolver.set_ElementBarriers(esriElementType.esriETJunction, juncElemBarriers);

                 netSolver.set_ElementBarriers(esriElementType.esriETEdge, edgeElemBarriers);

                 netSolver.SelectionSetBarriers = selSetBarriers;

                 INetworkAnalysisExtFlags naxFlags = m_utilNetExt as INetworkAnalysisExtFlags;


                 int edgeFlagCount = naxFlags.EdgeFlagCount;

                 if (edgeFlagCount > 0)


                     IEdgeFlag[] edgeFlags = new IEdgeFlag[edgeFlagCount];

                     for (int i = 0; i < edgeFlagCount; i++)


                         IEdgeFlagDisplay edgeFlagDisplay = naxFlags.get_EdgeFlag(i);

                         IFlagDisplay flagDisplay = edgeFlagDisplay as IFlagDisplay;

                         IEdgeFlag edgeFlag = new EdgeFlagClass();

                         edgeFlag.Position = Convert.ToSingle(edgeFlagDisplay.Percentage);

                         INetFlag netFlag = edgeFlag as INetFlag;

                         netFlag.UserClassID = flagDisplay.FeatureClassID;

                         netFlag.UserID = flagDisplay.FID;

                         netFlag.UserSubID = flagDisplay.SubID;

                         edgeFlags = edgeFlag;


                     tfs.PutEdgeOrigins(ref edgeFlags);



                 ITraceTasks traceTasks = m_utilNetExt as ITraceTasks;

                 tfs.TraceIndeterminateFlow = traceTasks.TraceIndeterminateFlow;

                 IEnumNetEID resultJuncs, resultEdges;

                 esriFlowElements flowElements = traceTasks.TraceFlowElements;

                 if (traceTasks.TraceEnds)


                     tfs.FindFlowEndElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges);



                     tfs.FindFlowElements(esriFlowMethod.esriFMUpstream, flowElements, out resultJuncs, out resultEdges);



             catch (System.Exception excep)





         protected override void OnUpdate()






0 Kudos
1 Reply
New Contributor II

Hi Maria MariaMaldini, I know it's probably outdated. But did you come up with a solution to this issue? 

I'm working on something similar to your previous work. And ran into exactly same problem. 



0 Kudos