Select to view content in your preferred language

How can I set my custom tool active in ArcMap?

2739
3
Jump to solution
09-17-2014 03:22 AM
SergeyGamayunov
Emerging Contributor

I've tried this snippet:

///<summary>Find a specific tool (or command) in a toolbar and set it to be active.</summary>

/// 

///<param name="application">An IApplication interface.</param>

///<param name="toolName">A System.String that is the name of the command to return. Example: "esriFramework.HelpContentsCommand"</param>

/// 

///<remarks>Refer to the EDN document http://edndoc.esri.com/arcobjects/9.1/default.asp?URL=/arcobjects/9.1/ArcGISDevHelp/TechnicalDocumen... for a listing of available CLSID's and ProgID's that can be used as the toolName parameter.</remarks>

public void SetToolActiveInToolBar(ESRI.ArcGIS.Framework.IApplication application, System.String toolName)

{

  ESRI.ArcGIS.Framework.ICommandBars commandBars = application.Document.CommandBars;

  ESRI.ArcGIS.esriSystem.UID commandID = new ESRI.ArcGIS.esriSystem.UIDClass();

  commandID.Value = toolName; // example: "esriArcMapUI.ZoomInTool";

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

 

  if (commandItem != null)

  application.CurrentTool = commandItem;

}

Buuuut, I have no idea, how run it. What should I get to ESRI.ArcGIS.Framework.IApplication application?

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Is your custom tool an Add-in? If so, you can always use "My.ArcMap.Application".

Otherwise, I would take a look at one of the walkthroughs (like Create a custom tool) which shows how to get the IApplication hook.

A private member variable (m_application) is provided and will be set in the OnCreate event (or method) as the hook object from the calling application passed into the DrawGraphicLine class. Since ArcMap consumes the custom .dll, the hook object (ArcMap.exe) is passed into the OnCreate event of the DrawGraphicLine class. This event sets the m_application variable which is of type ESRI.ArcGIS.Framework.IApplication and begins the entry point for your tool to perform its functionality.

View solution in original post

3 Replies
SergeyGamayunov
Emerging Contributor

"set*", not "get". 

0 Kudos
KenBuja
MVP Esteemed Contributor

Is your custom tool an Add-in? If so, you can always use "My.ArcMap.Application".

Otherwise, I would take a look at one of the walkthroughs (like Create a custom tool) which shows how to get the IApplication hook.

A private member variable (m_application) is provided and will be set in the OnCreate event (or method) as the hook object from the calling application passed into the DrawGraphicLine class. Since ArcMap consumes the custom .dll, the hook object (ArcMap.exe) is passed into the OnCreate event of the DrawGraphicLine class. This event sets the m_application variable which is of type ESRI.ArcGIS.Framework.IApplication and begins the entry point for your tool to perform its functionality.

SergeyGamayunov
Emerging Contributor

Thank you, sir 😃

0 Kudos