Addins button or tool

6762
12
03-01-2011 12:10 AM
bastianellmenreich
New Contributor
hello,
by using the addins i must choose tool or button. i will convert my 9.3 c# code to addin and will prevent an installer with registrations. so in 9.3 i have a tool wich inherit from basetool. the tool opens a form in the onclick method. in the mouse down events i capture the geometry and send it to the form. the new addin tool did not have a onclick method and the button no onmousedown event.
also i cannot call the tool from the form by setting application.currenttool = addins.tool because of it is no command.
so what is the new way to open a form, select somthing like geometrytype (point or line), enable any kind (drawing or editing) of digitize and get back the new geometry to form.

thanks
0 Kudos
12 Replies
BradChappell
New Contributor
They are not added automatically but you can add them yourself:

ESRI.ArcGIS.Desktop.AddIns.Tool

protected override void  OnMouseDown(MouseEventArgs arg)
protected override void OnMouseMove(MouseEventArgs arg)
protected override void OnMouseUp(MouseEventArgs arg)


ESRI.ArcGIS.Desktop.AddIns.Button

protected override void OnClick()
0 Kudos
bastianellmenreich
New Contributor
thanks for your answer.

i know both addins and there methods. unfortunatly i need a combination of both.

first i want to open an form if the user click on a button. i can do that by use a button.
then the user select a geometrytype (point, line or polygon) in the form. after that the form should enable a tool to capture the new geometry. the problem is how can i call a addin tool?

when the user click on a addin tool instead of a button, i can only open a from when the user click on the map but i need the formselection first.

one way i will try is to call an command such as the editor with its oncreatefeature event. but its very complex.

kind regards
0 Kudos
EdgarBejarano
Occasional Contributor
Hello.  So far I see that the class in your project where you are defining your ArcMap Add-In cannot have more than one ESRI.ArcGIS.Desktop.AddIns baseclass.  I tried the below and that will not work, and if I remove implementing the AddIns.Button baseclass, then I cannot have the OnClick().

public class Tool1 : ESRI.ArcGIS.Desktop.AddIns.Tool, ESRI.ArcGIS.Desktop.AddIns.Button
    {
        public Tool1()
        {
        }

        protected override void OnUpdate()
        {
            Enabled = ArcMap.Application != null;
        }

        protected override void OnClick()
        {
            //
            //  TODO: Sample code showing how to access button host
            //
            //ArcMap.Application.CurrentTool = null;
            System.Windows.Forms.MessageBox.Show("Hello OnClick");
        }

        protected override void OnMouseDown(MouseEventArgs arg)
        {
            System.Windows.Forms.MessageBox.Show("Hello OnMouseDown");
        }
    }

Essentially, you want to do something similar to the Measure tool in ArcMap, whereby clicking on the tool on the toolbar will launch a form, allow the end-user to make one or more selections, then interact with the map via the mouse event handlers.  You may have to consider the DLL registration/Inherit-from-BaseTool route again for that specific functionality or as the Add-In sample that implements various Add-In types demonstrates, which is to offer a button and a tool, separately.  That sample may demonstrate how one can interact (pass-on info) to the other, as long as they are within the same VB.NET or C# project.  If the button and tool do not demonstrate that interaction, it does seem that the tool and the dockable window will, because the dockable window gets updated with values based on user interaction with the tool.  Check out that sample Add-In.
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Custom_selection...
0 Kudos
PaulHedlund
New Contributor II
I am having the same problem with trying to handle a tool and button within the same Add-in. 

Is there any confirmation from ESRI on this?  Is this a limitation of Add-ins?  Classic COM extensibility could handle both ITool and ICommmand within the same button.
0 Kudos
KevinSigwart
New Contributor
When using the AddIn Tool, what you are looking for is the OnActivate() method.  It is essentially the same thing as the OnClick event within BaseTool or the ITool in previous versions.  When the Tool is selected in the toolbar it gets compressed and the OnActivate method is fired off.  Then when a new tool is selected, the tool is deselected/decompressed and the Deactivate method is fired off.
0 Kudos
ChrisSchmeissner
New Contributor II
Kevin,
Could you please post a snippit of how you would work with the OnActivate method. I have a button and a tool in my add-in. The button opens a form. Within this form a have a button that when clicked, I would like for it to activate the tool. The tool allows me to get the x,y locations from the map and then preform various tasks.  The add-in tool itself work just fine. However I do not know how to call this tool from the form. Thank you.
0 Kudos
KenBuja
MVP Esteemed Contributor
Here's an example of what I have for an add-in that uses a button on a form to start drawing on the map. the tool is named DrawTool


        Dim pUID As New ESRI.ArcGIS.esriSystem.UID
        Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem

        pUID.Value = My.ThisAddIn.IDs.DrawTool
        pCommandItem = m_application.Document.CommandBars.Find(pUID, False, False)
        m_application.CurrentTool = pCommandItem


0 Kudos
ChrisSchmeissner
New Contributor II
Here's an example of what I have for an add-in that uses a button on a form to start drawing on the map. the tool is named DrawTool


        Dim pUID As New ESRI.ArcGIS.esriSystem.UID
        Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem

        pUID.Value = My.ThisAddIn.IDs.DrawTool
        pCommandItem = m_application.Document.CommandBars.Find(pUID, False, False)
        m_application.CurrentTool = pCommandItem




Ken,

Fantastic! It worked perfectly. Thanks so much for your help.
0 Kudos
EricStrasa
New Contributor
Chris:
I am facing the same problem. Could you please post your complete code snippet here or by email?

Thanks
0 Kudos