4

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Oct 17, 2015 at 21:43

1 Answer 1

3

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?

answered Oct 18, 2015 at 20:17
1
  • 1
    I 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! Commented Oct 18, 2015 at 21:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.