Edit attribute data
This tutorial demonstrates how to build data editing workflows with your add-in, updating feature attribute data using the Inspector
class.
With the ArcGIS Pro SDK for .NET, you can extend ArcGIS Pro with your own unique tools and workflows. Using Microsoft Visual Studio and the Pro SDK, developers can build Pro add-ins and solution configurations that provide users with custom functionality specific to their organization or industry.
The ArcGIS Pro SDK provides an extensive Editing API that supports different data editing patterns based on your workflow. One of these patterns includes use of the Inspector
class for getting and setting feature attribute values.
In this tutorial, you will create an add-in that updates the attributes of selected features from a feature class you specify within your project that is based on an attribute name and a value that you provide in custom edit boxes.
Prerequisites
- Microsoft Visual Studio is required. See the ArcGIS Pro system requirements for latest version and compatibility.
- Install ArcGIS Pro version 3.0 or higher.
- Install the ArcGIS Pro SDK for .NET. See the Installation ProGuide for more information.
- This tutorial uses Pro SDK Community sample data.
Steps
Create a new ArcGIS Pro Add-In Visual Studio Project
Start Visual Studio.
Choose File > New > Project and then from the ArcGIS templates group, select ArcGIS Pro Module Add-in. Name the add-in project
Edit
.With Inspector By default, the
Config.daml
file opens in Visual Studio. TheModule1.cs
file contains add-in module code.Note also in the
Config.daml
file that theinsert
tag'sModule id
attribute matches the ID in theModule1.cs
file. Further, that theclass
attribute also matches the class name of the module.Name The ArcGIS templates group is located in Templates > Visual C# > ArcGIS. Confirm that the latest .NET Framework is selected.
Add Ribbon controls to your add-in
You will now add three controls to your add-in to be used on the ribbon.
Right-click the project and choose Add > New Item and then select the Visual C# empty class definition from the list of item templates.
When prompted, name the new class file
Attribute
and then click Add to close the dialog box.Name To U s e Edit Box.cs Repeat this action again to add another class definition file. This time name the new class file
Mod
.Value To S e t Edit Box.cs Right-click the project a third time and click Add > New Item and then from the ArcGIS Pro Add-ins group, select ArcGIS Pro button from the list of item templates.
When prompted, name the new class file
Update
and then click Add to close the dialog box. The ArcGIS Pro Button template provides the basic contents of the class file, as well as corresponding code in theValues Button.cs Config.daml
file for the ArcGIS Pro UI.
Update code for the controls
Open the
Attribute
file and replace the contents of the class with the following:Name To U s e Edit Box.cs This code sets the class to a Pro EditBox and the constructor sets and references an instance of the edit box in
Module1
(added in the next step). The code also sets the edit box text to an empty string.Use dark colors for code blocks Copy Open the
Mod
file and replace the contents of the class with the following:Value To S e t Edit Box.cs Use dark colors for code blocks Copy Update the
Update
file and add the following line to theValues Button.cs O
method:n Click This code allows the button’s
O
method to run then Click Update
method that are added toValues Module1
in a subsequent step.Use dark colors for code blocks Copy
Update code in the Config.daml
and Module1.cs
files
Open the
Config.daml
file and replace the contents of the groups and controls sections with the following:This code updates:
The
Controls
section, adding edit box controls to the UI and setting their attributes; it also updates the button values.The
Groups
section, with updated caption and order. The new controls group will be shown on the Add-In tab.
Use dark colors for code blocks Copy Open the
Module1.cs
file and paste the following below theOverrides
region:It is helpful to consolidate business logic in the Module when possible. This code provides the following:
- References the edit box controls for their use in the module.
- Includes a new method,
Update
, which will be called by the button. This method does the following:Values - Defines a
Queued
in which to call synchronous methodsTask - Checks to make sure that conditions are met for the edit operation to be attempted with the
Inspector
, such as:- Checks for an active
mapview
- Checks for a selected layer in the Contents pane, and that it is for a feature layer with selected records
- Checks that the two edit boxes are populated, and checks that the attribute name is a valid attribute name for the feature layer
- Checks for an active
- Defines a
- Provides a messagebox with a list of the parameters to be used in the editing operation
- Creates an
Inspector
andEdit
Operation - Runs the
Inspector
to calculate the attributes - Applies the
Edit
Operation
Use dark colors for code blocks Copy
Build and test your code
Once your code is complete, build your project and debug any issues. Start ArcGIS Pro, and when the start page appears, select the previously-installed ArcGIS Pro sample project
C:\Data\Feature
.Test\Feature Test.aprx When the project has loaded, from the Add-In tab, find your new add-in’s group labeled Update Attributes with Inspector. This confirms that your add-in was properly built and added. Next, select a feature layer from the Contents pane, such as
Test
, and right-click to open its attribute table view. Select a few records and update their Description attribute. Ensure you have the correct layer selected in the TOC, and a few features selected and shown in the attribute table.Points Enter values into your add-in’s edit boxes:
For attribute name, enter
Description
.Since the TestPoints’ Description attribute is a string, enter any value.
Click Update Values to run the edit operation and update the selected records. The operation should report if a step is missing, and confirm if the edit operation completed successfully.
If the operation completes successfully, confirm that your value was applied to the selected records.
What's Next?
Learn how to use additional ArcGIS Pro SDK for .NET features in these tutorials: