I am creating a tool for ArcGIS Desktop that will execute a command when I click a place on the map.
The Code looks like this:
public class TileLasLoader_Tool : ESRI.ArcGIS.Desktop.AddIns.Tool
{
private static EsriTools.Forms.TileLasLoader_Form _form;
ICommandItem _previousCommand = null;
public TileLasLoader_Tool()
{
_form = EsriTools.Forms.TileLasLoader_Form.instance;
}
protected override void OnUpdate()
{
}
protected override void OnMouseDown(MouseEventArgs arg)
{
base.OnMouseDown(arg);
if (arg.Button == MouseButtons.Left)
{
_form.LoadLasFile(arg.X, arg.Y);
ArcMap.Application.CurrentTool = _previousCommand;
}
}
My Only problem is getting the tool to revert back to the previous "Command Item" that it was before I used the tool. If it was not using a tool I would just make it null so it reverts back to the windows mouse cursor.
1 Answer 1
The Interface IApplication
has a property called CurrentTool which will return the currently active tool.
I'm not aware of any Application level event listener for commands.
I'm not sure what I'm about to suggest is a smart way of doing this but why not put the IApplication
.CurrentTool into your custom button onUpdate() function and constantly update some global variable _previousCommand
? I do not know if this would have an impact on performance?
-
1I did that once! I first tried placing it in the constructor for the tool and it worked until I used to tool again! It reverted back to the "first" previous tool! I then placed it in the "onupdate" function to where it trigger my tool as the previous tool!Chris Stayte– Chris Stayte2015年10月18日 21:10:46 +00:00Commented Oct 18, 2015 at 21:10