0

I have inherited a C# ESRI (ArcMap) add-in that needs a UI tweak (the rest of the changes are completed). And I had no previous experience with such add-ins before starting on this.

The add-in in question has a DockableWindow, but I need to be able to click on the map and get the coordinates of the click (the inherited version required typing in the coordinates manually).

Research indicated that the only way to do this was to create a new class inheriting from a Tool, and use OnMouseDown()/OnMouseUp() to do the work. (I did try overriding OnMouseClick() in the DockableWindow, but that seems to only capture clicks within the DockableWindow. Not a huge surprise there.)

In any event, I created the Tool, added a line for it in the .esriaddinx file, and saw that it was added to ThisAddIn.IDs.

Everything I've read seems to indicate that the next steps are to get the UID for it, do a Find on the document's command bars using that UID, then set the app's currentTool to my tool.

The only problem is that, when I try this, the Find always returns null.

I've even tried creating my own command bar, adding the Tool to that command bar, displaying the command bar, and doing the Find on that command bar. Still, I always get null.

Is there another step that I'm missing? (And sorry about the lack of actual code; the development machine is not near a computer connected to the internet.)

  • So, if I'm understanding you, you click on the dockable window which makes the application current tool your new tool then you want to click (mousedown) on the active view and do something. is that correct so far? Have a read of resources.arcgis.com/en/help/arcobjects-net/componenthelp/… your tools' GUID should be in your Config.esriaddinx file in the AddInID enclosure which makes it easier to find, copy and paste. Does that help any? – Michael Stimson Jan 3 '18 at 3:17
1

It is hard to say without seeing your code and config, but here is how I have a tool set up in one of my projects. Hopefully something will jump out at you.

Config:

...
<Commands>
    <Tool id="big_long_id_customTool" class="customTool" message="some message" caption="some caption" 
    tip="some tip" category="" image="Images\custom.png" cursor="Images\custom.cur" />
</Commands>
<DockableWindows>
    <DockableWindow id="big_long_id_dockable_window" class="dockWindow+AddinImpl" caption="window" image="Images\window.png">
        <InitialPlacement height="775" width="350" state="pinned" position="left" />
    </DockableWindow>
</DockableWindows>
...

Select Tool:

UID pUID = new UID();
pUID.Value = ThisAddIn.IDs.customTool;
ICommandItem pCommandItem = ArcMap.Application.Document.CommandBars.Find(pUID, false, false);
ArcMap.Application.CurrentTool = pCommandItem;
-1

Thanks, both of you. The code that you both mentioned is exactly what I had for that part of it (the 'Everything I've read...' part above). I think what was tripping me up is that I needed the Tool and the DockableWindow to communicate, and my initial attempt to get around that was to have the DockableWindow create the Tool, passing a reference to itself in the Tool's constructor.

By the time I found the code that you both mentioned, I had forgotten about that argument.

I took a new approach after posting this, having the Tool created in the same Toolbar with the DockableWindow (within the Config.esriaddinx). When I added that, I noticed the argument, eliminated it, and replaced it with a static method in the DockableWindow that allowed the Tool to find a reference.

Long story short, that all worked. (And now I wish I had been able to cut-n-paste the code over. sigh) Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.