TitlePages

Wednesday 19 November 2014

Create a Display Flow Arrows Addin


ArcMAP ESRI Add-in for Display flow arrows for Utility Geometric Network


Software Required:
Microsoft Visual Studio 2010 +
ArcMap 10.2 or more
ArcObjects SDK for .Net Installed

Procedure:

  • Open Visual Studio 2010
  • Create a New Project > Visual C#> ArcGIS>Desktop Addins >ArcMap Add In
  • ArcMap Addin Wizard will appear on the Screen.Give a desired name for your Addin and click Next
  • In the Addin Types Enable Button checkbox and provide description for it.This will appear as a button tooltip in your ArcMap application.Click finish to end the wizard.
  • Now go the Solution Explorer(View>Soln Explorer) and open the Addinname.cs file if it doesn't appear in your screen.
  • Replace the content of the file with the following data.
  • Add the References(Right click references in Solution Explorer and select Add References) based on your classes usage


//Add the references in to the current namespace
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.EditorExt;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.NetworkAnalystTools;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;



namespace Flow
{
    public class FlowArrow : ESRI.ArcGIS.Desktop.AddIns.Button
    {
//Declare the interface Variable
        public IUtilityNetworkAnalysisExtFlow utilarr;
        public IUtilityNetworkAnalysisExt utilflow;
        public INetworkAnalysisExt netExt;

        public FlowArrow()
        {
//Get the reference to the Utility Analyst Toolbar using the UID Reference
            UID pUID = new UIDClass();
            pUID.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
            netExt = ArcMap.Application.FindExtensionByCLSID(pUID) as INetworkAnalysisExt;

            UID uidutilflow = new UIDClass();
            uidutilflow.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
            utilflow = ArcMap.Application.FindExtensionByCLSID(uidutilflow) as IUtilityNetworkAnalysisExt;

            
            
        }

        protected override void OnClick()
        {
            message m = new message();
    
            IGeometricNetwork gn = null;
            
            // get the current network

            IMxDocument mxd=ArcMap.Application.Document as IMxDocument;
            IMap map=mxd.FocusMap;
            IActiveView av = map as IActiveView;
            gn = netExt.CurrentNetwork;

            if (gn != null && utilflow!= null)
            {
                utilflow = netExt as IUtilityNetworkAnalysisExt;
                utilarr = utilflow as IUtilityNetworkAnalysisExtFlow;
                utilarr.ShowFlow = !(utilarr.ShowFlow);
                av.Refresh();
            }

       
            
            // refresh the display to update the flow direction arrows
            IActiveView mapView = ArcMap.Document.ActiveView;
            mapView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

        }
        protected override void OnUpdate()
        {
//Enable the Button once the operation is Successful
           //Enabled=True;
        }

        
   
    }

}

Code to get flow arrow using ArcObjects
Display flow arrow using Arcobjects

  • Save your Current project .Don't run your Code.
  • Go to Properties>Addinname Properties>Debug option.Set your ArcMap as the External program for debugging the code
  • Run the Code.
  • ArcMap Application will open.Now go to Customize>Customize mode>Command.Right now you will see your Addin name in the category list click on it.After that the button will get displayed on the commands window.
  • Drag the Button and put it in the Menu bar.
  • You get the ESRI Addin file bin>Debug folder of your project location
  • Now its party time :) Share your work with other through the Addin file



No comments: