Select to view content in your preferred language

How to know clicked tool name (Ex. Move or Modify vertex)

434
2
02-16-2022 03:10 AM
JonnalagaddaRavisankara
New Contributor

Hi All,

I need to validate the tool before completing my task. if I click move tool I have a different workflow, if I edit vertices I have another workflow. How to know the clicked tool.

 

Thank you,

 

0 Kudos
2 Replies
RobBurke
Occasional Contributor

I am not sure this is what you are looking for, but it may be helpful to use some kind of Event.

You could subscribe to the ActiveToolChangedEvent.

For example you could subscribe to the event in a dockpane's constructor.

protected Dockpane1ViewModel()
{

     ArcGIS.Desktop.Framework.Events.ActiveToolChangedEvent.Subscribe(OnActiveToolChanged);
}

And then create you own function OnActiveToolChanged to determine which tool was clicked.

 

Below the initialize method’s code, add the following new method.  The code does an unsubscribe, so that the MessageBox stops appearing.  Instead of a message box, make your decision on what to do, depending on the tool clicked.


private void OnActiveToolChanged(ArcGIS.Desktop.Framework.Events.ToolEventArgs args)
{
string prevTool = args.PreviousID;
string newTool = args.CurrentID;
MessageBox.Show(prevTool, newTool);
ArcGIS.Desktop.Framework.Events.ActiveToolChangedEvent.Unsubscribe(OnActiveToolChanged);
}

Robert Burke
0 Kudos
BerndtNording
Regular Contributor

If you need to do something before the tool is used, then use ActiveToolChangedEvent mentioned, but if what you are doing occurs when the tool actually does something, then just get the active tool - there's only one.

      Tool currentTool = FrameworkApplication.ActiveTool;
      MessageBox.Show(currentTool.Caption);
0 Kudos