arcmap Add-in创建的button中如何调用ArcMap自带或自定义的工具

arcmap Add-in创建的button中如何调用ArcMap自带或自定义的工具


另外, ArcMap中具体UID值参考下面连接:




ESRI.ArcGIS.Framework.ICommandBars commandBars = null;

ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
uid.Value = esriArcMapUI.ZoomInTool;
//or {AD1891E4-7C79-11D0-8D7C-0080C7A4557D};

ESRI.ArcGIS.Framework.ICommandItem commandItem = commandBars.Find(uid, false, false);

  if (commandItem != null)


///<summary>Zooms to the selected layer in the TOC associated with the active view.</summary>
///<param name="mxDocument">An IMxDocument interface</param>
public void ZoomToActiveLayerInTOC(ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument)
  if(mxDocument == null)
  ESRI.ArcGIS.Carto.IActiveView activeView = mxDocument.ActiveView; 

  // Get the TOC
  ESRI.ArcGIS.ArcMapUI.IContentsView IContentsView = mxDocument.CurrentContentsView;

  // Get the selected layer
  System.Object selectedItem = IContentsView.SelectedItem;
  if (!(selectedItem is ESRI.ArcGIS.Carto.ILayer))
  ESRI.ArcGIS.Carto.ILayer layer = selectedItem as ESRI.ArcGIS.Carto.ILayer; 

  // Zoom to the extent of the layer and refresh the map
  activeView.Extent = layer.AreaOfInterest;

获取Network Analyst的扩展功能

public ESRI.ArcGIS.NetworkAnalystUI.INetworkAnalystExtension GetNetworkAnalystExtension(ESRI.ArcGIS.Framework.IApplication application)

  ESRI.ArcGIS.esriSystem.IExtension extension = 
  application.FindExtensionByName("Network Analyst");
  ESRI.ArcGIS.NetworkAnalystUI.INetworkAnalystExtension networkAnalystExtension =
   extension as ESRI.ArcGIS.NetworkAnalystUI.INetworkAnalystExtension; // Dynamic Cast

  return networkAnalystExtension;

public void AddScalebar(ESRI.ArcGIS.Carto.IPageLayout pageLayout, ESRI.ArcGIS.Carto.IMap map)

  if (pageLayout == null || map == null)
  ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
  envelope.PutCoords(0.2, 0.2, 1, 2); // Specify the location and size of the scalebar
  ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
  uid.Value = "esriCarto.AlternatingScaleBar";

  // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
  // Activate it and add it to the PageLayout's graphics container
  ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast
  ESRI.ArcGIS.Carto.IActiveView activeView = pageLayout as ESRI.ArcGIS.Carto.IActiveView; // Dynamic Cast
  ESRI.ArcGIS.Carto.IFrameElement frameElement = graphicsContainer.FindFrame(map);
  ESRI.ArcGIS.Carto.IMapFrame mapFrame = frameElement as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
  ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
  ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
  element.Geometry = envelope;
  graphicsContainer.AddElement(element, 0);
  ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;

  ESRI.ArcGIS.Carto.IScaleBar markerScaleBar = ((ESRI.ArcGIS.Carto.IScaleBar)(mapSurround));
  markerScaleBar.LabelPosition = ESRI.ArcGIS.Carto.esriVertPosEnum.esriBelow;

Application CoClass

ArcObjects Library Reference (ArcMap)	 
Application CoClass
Esri ArcMap Application

Product Availability
Available with ArcGIS Desktop.
Supported Platforms
Interfaces	Description
IApplication (esriFramework)	Provides access to members that query or modify the application.
IApplicationStatus (esriFramework)	Provides access to the applications status.
IApplicationWindows (esriArcMapUI)	Provides access to members that control the DataWindow Container.
IDockableWindowManager (esriFramework)	Provides access to a method that finds a dockable window in the application.
IEnumPrinterNames (esriArcMapUI)	Provides access to an enumeration of all the Printers.
IExtensionManager (esriSystem)	Provides access to members that query extension.
IGxApplication (esriCatalogUI)	Provides access to members that control the Gx Application object.
IGxCatalogDefaultDatabase (esriCatalog)	Provides access to members that manages a GX catalog default geodatabase.
IGxCatalogWorkspace (esriCatalog)	Provides access to members that manages a GX catalog workspace.
IMultiThreadedApplication (esriFramework)	Provides access to members that control DLL thread managers.
IMxApplication (esriArcMapUI)	Provides access to members that control the Mx Application.
IMxApplication2 (esriArcMapUI)	Provides access to members that control the Mx Application.
IObjectFactory (esriFramework)	Provides access to members that allow automation clients to create arbitrary objects within the application's process space.
IVbaApplication (esriFramework)	Provides access to members that modify the VBA projects in this application.
IWindowPosition (esriFramework)	Provides access to members that query or modify a window's position, size and state.
Event Interfaces
Interfaces	Description
IApplicationStatusEvents (default)	Provides access to events fired by application.
The Application object is the core object in the ArcMap and ArcCatalog applications. This object represents the application itself and acts as the central point where access is gained to other objects in the system. The Application object's primary interface is IApplication.

Instantiating a new MxDocument starts a new ArcMap application.  Cocreating a new MxDocument actually creates a new Application object which in turn co-creates a new MxDocument.

Working with Events


// Get the TOC
            IDockableWindowManager pDocWinMgr = ArcMap.DockableWindowManager as IDockableWindowManager;
            UID uid = new UIDClass();
            uid.Value = "{368131A0-F15F-11D3-A67E-0008C7DF97B9}";
            IDockableWindow pTOC = pDocWinMgr.GetDockableWindow(uid);
            if (pTOC.IsVisible())
                System.Windows.Forms.MessageBox.Show(pTOC.Caption + "(" + pTOC.Name + ")");


IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;

            //Data View转为Layout View:  OK 
            //mxdoc.ActiveView = mxdoc.PageLayout as IActiveView;

            //Layout View转为Data View:  OK
            mxdoc.ActiveView = mxdoc.FocusMap as IActiveView;   
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页