Select to view content in your preferred language

Addins button or tool

7854
12
03-01-2011 12:10 AM
bastianellmenreich
Emerging 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
ChrisSchmeissner
Emerging Contributor
In the code below btnMapTool is the button on my form I want to launch the Tool. Tool1 is the name of the tool. Hope this helps.

Private Sub btnMapTool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMapTool.Click
        Dim pUID As New ESRI.ArcGIS.esriSystem.UID
        Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem

        pUID.Value = My.ThisAddIn.IDs.Tool1
        pCommandItem = m_app.Document.CommandBars.Find(pUID, False, False)
        m_app.CurrentTool = pCommandItem
End Sub

'************Below is the top portion of my Tool1 class.

Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Geodatabase
Imports System.Xml.Linq
Imports System.Windows.Forms
Imports ESRI.ArcGIS.ArcMapUI

Public Class Tool1
    Inherits ESRI.ArcGIS.Desktop.AddIns.Tool

    Private Shared s_tool As Tool1


    Private m_app As ESRI.ArcGIS.Framework.IApplication = ArcMapAddin2.My.ArcMap.Application
    Private MxDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument = ArcMapAddin2.My.ArcMap.Document

  Public Sub New()
        s_tool = Me

    End Sub
    Friend Shared Function GetTool() As Tool1
        If s_tool Is Nothing Then
            Dim toolID As UID = New UIDClass()
            toolID.Value = ArcMapAddin2.My.IDs.Tool1
            ArcMapAddin2.My.ArcMap.Application.FindExtensionByCLSID(toolID)
        End If

        Return s_tool
    End Function

  Protected Overrides Sub OnUpdate()
    Enabled = My.ArcMap.Application IsNot Nothing
    End Sub
   
  
    Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)
        MyBase.OnMouseDown(arg)
        'Get the active view from the ArcMap static class.
        Dim activeView As IActiveView = My.ArcMap.Document.ActiveView

        '****************************************************************************************************
        'Get the X, Y coordinate from the point the tool was clicked
        Dim point As IPoint
        Dim DisplayTransform As IDisplayTransformation
        point = New ESRI.ArcGIS.Geometry.Point
        DisplayTransform = MxDoc.ActiveView.ScreenDisplay.DisplayTransformation
        point = DisplayTransform.ToMapPoint(arg.X, arg.Y)
        point.PutCoords(point.X, point.Y)
        'MsgBox("x = " & point.X & " y = " & point.Y)
'*************More Code for the tool goes here
End Sub
0 Kudos
EricStrasa
New Contributor
Chris:
Indeed, thanks. All I had in 8 hours was a lame iTool extension:

Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Geometry


Public Class Tool1
    Inherits ESRI.ArcGIS.Desktop.AddIns.Tool
    Private frm As New Form1

    Public Sub New()
        frm.Visible = True
        frm.Activate()
    End Sub

    Protected Overrides Sub OnUpdate()
        Enabled = My.ArcMap.Application IsNot Nothing
    End Sub

    Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)
        MyBase.OnMouseDown(arg)
        Dim mxDoc As IMxDocument = My.ArcMap.Application.Document
        Dim activeView As IActiveView = TryCast(mxDoc.FocusMap, IActiveView)
        Dim nPoint As IPoint = TryCast(activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y), IPoint)
        System.Windows.Forms.MessageBox.Show("Screen X=" + arg.X.ToString + ", Y= " + arg.Y.ToString)
        System.Windows.Forms.MessageBox.Show("Map X=" + nPoint.X.ToString + ", Y= " + nPoint.Y.ToString)
        frm.txtX.Text = nPoint.X.ToString
        frm.txtY.Text = nPoint.Y.ToString
        frm.Activate()
    End Sub

End Class

Is the ArcMapAddin2 another Arcgis Tool button added to the project via Microsoft Visual Studio or how is this done?
0 Kudos
ScottParker
New Contributor
Thanks, I used a couple line of your code to activate a tool from a dockable window.

cschmeissner;135749 wrote:
In the code below btnMapTool is the button on my form I want to launch the Tool. Tool1 is the name of the tool. Hope this helps.


Private Sub btnMapTool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMapTool.Click
        Dim pUID As New ESRI.ArcGIS.esriSystem.UID
        Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem

        pUID.Value = My.ThisAddIn.IDs.Tool1
        pCommandItem = m_app.Document.CommandBars.Find(pUID, False, False)
        m_app.CurrentTool = pCommandItem
End Sub
0 Kudos