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

arcmap Add-in创建的button中如何调用ArcMap自带或自定义的工具
1,Add-in创建的button中如何调用ArcMap自带的工具以及Add-in自定义的工具?
2,别人创建的Add-in,怎么查看该UID?

【解决办法】:
1,通过ArcMap中命令的UID值可以获取该命令,参考下面链接。
http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//0049000000n0000000

另外, ArcMap中具体UID值参考下面连接:
http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#//00010000029s000000

自定义Add-in也是如此,UID值可以在该Add-in工程的Config.esriaddinx文件中查看,如下面有,即为该自定义Button的UID值。

2,如果是别人创建的Add-in,应该会给你一个以.esriAddin结尾的文件,将其后缀改为zip,然后解压,里面有Config.xml文件,以记事本打开,进行查看即可。​

调用Bars中命令工具方法

ESRI.ArcGIS.Framework.ICommandBars commandBars = null;
commandBars=ArcMap.Application.Document.CommandBars;

ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
uid.Value = esriArcMapUI.ZoomInTool;
//or {AD1891E4-7C79-11D0-8D7C-0080C7A4557D};
//自定义Add-in的UID为ArcMapAddin1_Tool1; 

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

  if (commandItem != null)
        commandItem.Execute();

toc图层管理调用方法

///<summary>Zooms to the selected layer in the TOC associated with the active view.</summary>
/// 
///<param name="mxDocument">An IMxDocument interface</param>
///  
///<remarks></remarks>
public void ZoomToActiveLayerInTOC(ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument)
{
  if(mxDocument == null)
  {
    return;
  }
  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))
  {
    return;
  }
  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;
  activeView.Refresh();
}

获取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)
  {
    return;
  }
  
  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;
  element.Activate(activeView.ScreenDisplay);
  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;
  markerScaleBar.UseMapSettings();
}

Application CoClass

http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//000t00000002000000

ArcObjects Library Reference (ArcMap)	 
Application CoClass
Esri ArcMap Application

Product Availability
Available with ArcGIS Desktop.
Supported Platforms
Windows
Interfaces
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.
Remarks
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

右边显示toc图层管理pad

// 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())
            {
                pTOC.Dock(esriDockFlags.esriDockRight);
                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;   
            mxdoc.ActiveView.Refresh();
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页