ProGuide Build your first add in - Esri/arcgis-pro-sdk GitHub Wiki

This guide demonstrates how to build an ArcGIS Pro add-in.

Language:      C#
Subject:       Framework
Contributor:   ArcGIS Pro SDK Team <[email protected]>
Organization:  Esri, http://www.esri.com
Date:          10/06/2024
ArcGIS Pro:    3.4
Visual Studio: 2022

Prerequisite: Before you can build your first add-in, you have to install ArcGIS Pro and the corresponding version of the ArcGIS Pro SDK on your development machine. For details on how to install the ArcGIS Pro SDK you can follow the installation instructions in this ProGuide: Install ArcGIS Pro SDK for .NET.

Step 1

Open Visual Studio and select New Project.

New Project

Step 2

On the New Project dialog box, expand the Templates\Visual C#\ArcGIS or Templates\Visual Basic\ArcGIS folder. Select the ArcGIS Pro Add-ins folder (you may have other folders there if you also have the ArcObjects 10.x SDK for .NET installed).

Step 3

The ArcGIS Pro Module Add-in Visual Studio project item template displays. Select it and type ProAppModule1 for the name. Change the location or accept the default. Click OK.

NewModuleAddin

Step 4

Visual Studio creates a new Visual C# or Visual Basic project for you. For the purposes of this document, Visual C# will be assumed; however, the procedure is almost identical for Visual Basic. You will notice the following content in your new project:

NewContent

The Config.daml file opens (by default) in Visual Studio. The Module1.cs file contains your add-in module code. The code will be similar to this:

internal class Module1 : Module {

    private static Module1 _this = null;

	/// <summary>
    /// Retrieve the singleton instance to this module here
    /// </summary>
    public static Module1 Current => _this ?? = 
          (Module1)FrameworkApplication.FindModule("ProAppModule1_Module");
  }

Note that the module contains a private reference to your module instance, which is a singleton. The string "ProAppModule1_Module" is your module ID. Framework uses this ID to reference your module in the DAML file and to find your associated module instance in the FindModule method of the FrameworkApplication module. By default, your module class is called Module1. The default namespace is the name you entered on the New Project dialog box, which in this case, is ProAppModule1.

Note also in the Config.daml file that the id attribute of the insertModule tag matches the ID within the Module1.cs file and the className attribute also matches the class name of the module.

<modules>
    <insertModule id="ProAppModule1_Module" className="Module1" autoLoad="false" caption="Module1">

Step 5

Compile and build the project. If you have errors in your output window, check that you have the ArcGIS Pro application and the ArcGIS Pro SDK for .NET correctly installed. As long as you have not changed the syntax in any of the generated files (from the Project template), there should be no compilation errors.

Step 6

Open Windows Explorer. Navigate to the C:\Users\<Your user name>\Documents\ArcGIS\AddIns\ArcGISPro folder. You should see the add-in folder for your newly compiled add-in. The name of the folder corresponds to the ID (GUID) of your add-in.

<AddInInfo id="{8e95b131-d203-4775-9617-07481fbdfa32}" ...

Double-click the folder. You will see your add-in file within the folder.

guid-folder2

Step 7 Right-click the project title within Visual Studio and select Add > New Item from the Project Context menu.

AddNewItem

From the Visual Studio Add New Item dialog box, choose ArcGIS Pro Button from the list of available ArcGIS Pro SDK Item templates. Keep the default name Button1.cs and click OK.

NewButton

Step 8

Within Visual Studio you should now see a new file, Button1.cs, that has been added to your project. Double-click that file and type the following code into the OnClick method:

 internal class Button1 : Button {

    protected override void OnClick() 
    {
      string uri = ArcGIS.Desktop.Core.Project.Current.URI;
           ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show($"Project uri {uri}");
    }
 }

Step 9

Build and compile your add-in.

Step 10

Place a breakpoint in the margin of your OnClick method and run your add-in in the Visual Studio debugger.

Breakpoint

Step 11

ArcGIS Pro starts. Allow ArcGIS Pro to complete its initialization. Create a new empty project using the template of your choice or open one of your existing projects. NewProProject

Step 12

Click Add-In tab and click the Button 1 add-in button.

AddinTab

Step 13

Your breakpoint will be hit in Visual Studio. Press F5 or click the Continue button to continue execution. The following message box displays.

Breakpoint2 NewProProject2

Click OK. Stop debugging.

⚠️ **GitHub.com Fallback** ⚠️