Introduction to Arc GIS AddIns Exercises GISLIS Conference

  • Slides: 22
Download presentation
Introduction to Arc. GIS Add-Ins Exercises GIS/LIS Conference, 2014 Rochester, MN

Introduction to Arc. GIS Add-Ins Exercises GIS/LIS Conference, 2014 Rochester, MN

Exercise 1 – Add-Ins with Python In this exercise you will be using the

Exercise 1 – Add-Ins with Python In this exercise you will be using the Python Add-In Wizard and Py. Scripter to create an Add-In to Arc. Map that contains a toolbar with a tool for creating a map package file (. mpk). 1. Open the Python Add-In Wizard by Double-clicking on the Add. In Assistant shortcut on your desktop. 2. The first thing you’ll need to do is define your Add-In project root folder. Navigate to C: tempIntroductionto. Add. Insfor. Arc. GISExercise 1 and create a folder called ‘Create. Map. Package’ Click ‘OK’ Introduction to Arc. GIS Add-ins 2

3. In the Wizard window that appears enter the information as shown in the

3. In the Wizard window that appears enter the information as shown in the graphic to the right. Select Product: Arc. Map Name: Create Map Package Tool Version: 1. 0 Company: MN DNR Description: Provides a tool to create a map package based on the user defined extent. Author: <your name here> Image: C: tempIntroduction to Add. Ins for Arc. GISExercise 1 Package 64. png. 4. Click on the ‘Add-In Contents’ Tab Introduction to Arc. GIS Add-ins 3

5. In the contents tab you can define buttons/tools/etc to be included in the

5. In the contents tab you can define buttons/tools/etc to be included in the add-in. Add a toolbar by right -clicking on the TOOLBARS item and select ‘New Toolbar’. Enter the information as shown in the graphic below. Caption: Map Package ID: Create. Map. Package_addin. mpktoolbar Show Initially: Checked Introduction to Arc. GIS Add-ins 4

6. Under your new Map Package toolbar add a new Tool by right-clicking on

6. Under your new Map Package toolbar add a new Tool by right-clicking on the ‘Map Package’ item and select ‘New Tool’. Enter the information as shown in the graphic below. Caption: Create Map Package Class Name: Create. MPKTool ID: Create. Map. Package_addin. mpktool Tooltip: Create Map Package Message: Create Map Package for user defined extent Help Heading: Create Map Package Help Content: Create Map Package for user defined extent Image: C: tempIntroduction to Add. Ins for Arc. GISExercise 1 Package 16. png Introduction to Arc. GIS Add-ins 5

7. Next add an extension that will listen for changes to the Active View.

7. Next add an extension that will listen for changes to the Active View. Add an extension by right-clicking on the ‘EXTENSIONS’ item and select ‘New Extension’. Enter the information as shown in the graphic below. Name: Create Map Package Class Name: Create. MPKExt ID: Create. Map. Package_addin. mpkext Description: Checks Active View and disables Create Map Package if the Active View is Page Layout Methods to Implement: Active. View. Changed Click ‘Save’. The Add-In structure is created in the C: tempIntroductionto. Add. Ins for. Arc. GISExercise 1 Create. Map. Package folder Introduction to Arc. GIS Add-ins 6

8. The Add-In structure has been created in the C: tempIntroductionto. Add. Insfor Arc.

8. The Add-In structure has been created in the C: tempIntroductionto. Add. Insfor Arc. GISExercise 1Create. Map. Package folder. The next step is to modify the code behind the tool and extension so that they perform as expected. Open Windows Explorer and navigate to C: tempIntroductionto. Add. Insfor. Arc. GISExercise 1Create. Map. PackageInstall. Right-click on the Create. Map. Package_addin. py file and select ‘Edit With Py. Scripter’. Introduction to Arc. GIS Add-ins 7

9. Some custom code needs to be added to this file. For simplicity, the

9. Some custom code needs to be added to this file. For simplicity, the code is sitting in a text file at C: tempIntroductionto. Add. Insfor. Arc. GISExercise 1custom. Code. txt. Open this file and copy its contents. Replace ALL of the code in the Create. Map. Package_addin. py and then Save your Changes (File Save). It should look similar to the screen shot below: Introduction to Arc. GIS Add-ins 8

10. All the pieces are now ready to be compiled into the ESRI Add-In.

10. All the pieces are now ready to be compiled into the ESRI Add-In. Go to C: tempIntroductionto. Add. Insfor. Arc. GISExercise 1Create. Map. Package and double-click on the makeaddin. py file. This will create the add-in file in the same directory. 11. Install the Add-in. To do this, double-click on the file (C: tempIntroductionto. Add. Insfor. Arc. GISExercise 1Create. Map. Package. esriaddin). When the Installation Utility appears click on ‘Install Add-In’. Introduction to Arc. GIS Add-ins 9

12. Now test the add-in. Launch Arc. Map and open the sample project at

12. Now test the add-in. Launch Arc. Map and open the sample project at C: tempIntroductionto. Add. Insfor. Arc. GISExercise 1sample. Map. mxd. 13. Turn on the Create Map Package Extension by going to Customize Extensions and checking “on” the Create Map Package extension. Your new toolbar should be visible with your one tool. If it’s not, go to Customize Toolbars and turn on the Create Map Package toolbar. To use the tool select it and then click and drag a rectangle on the map. All data within that rectangle will be extracted and bundled and saved out to a map package located next to the sample. Map. mxd called sample. Map. mpk. Introduction to Arc. GIS Add-ins 10

Exercise 2 – Add-Ins with Visual Studio In this exercise you will be using

Exercise 2 – Add-Ins with Visual Studio In this exercise you will be using Visual Studio Express 2010 to create an Add-In to Arc. Map that contains a toolbar with two tools – one for finding upstream watersheds and one for finding downstream watersheds from a user’s mouse-click. 1. Open Visual Studio by Double-clicking on the Visual Studio shortcut on your desktop or from the Start menu. 2. Select “New Project” from the options on the left side of the window that opens. 3. Select “Desktop Add-Ins” on the left side, “Arc. Map Add-in” from the middle pane, and at the bottom of the New Project window type in “Watershed. Tools” for the name of your Add-in project. Click ‘OK’. Introduction to Arc. GIS Add-ins 11

4. Enter the information as shown in the graphic to the right. Add-in Name:

4. Enter the information as shown in the graphic to the right. Add-in Name: Watershed. Tools Company: MN DNR Author: <your name here> Description: These tools are for analyzing watersheds. Image: C: tempIntroduction to. Add. Insfor. Arc. GISExercise 2 Watershed. png. Click ‘Next’ Introduction to Arc. GIS Add-ins 12

5. Enter the information as shown in the graphic to the right. Add-in Type:

5. Enter the information as shown in the graphic to the right. Add-in Type: Tool Class Name: tool. Upstream Caption: Find Upstream Watersheds Image: C: tempIntroduction to Add. Ins for Arc. GISExercise 2Upstream. png Category: Watershed On Demand: Checked Tooltip: Find Upstream Watersheds Description: This tool selects all watersheds upstream of a user’s click Click ‘Finish’ A new project is created with the parameters that you’ve chosen – an Add-in with an upstream tool. The next step is to add the downstream tool. Introduction to Arc. GIS Add-ins 13

6. Next you’ll add the 2 nd tool to your project. To do this

6. Next you’ll add the 2 nd tool to your project. To do this go to Project Add New Item. Select the options as shown below: Installed Template: Desktop Add-ins Type: Add-in Component Name: tool. Downstream. vb Click ‘Add’ Introduction to Arc. GIS Add-ins 14

7. Enter the information as shown in the graphic to the right. Add-in Type:

7. Enter the information as shown in the graphic to the right. Add-in Type: Tool Class Name: tool. Downstream Caption: Find Downstream Watersheds Image: C: tempIntroductionto. Add. Ins for. Arc. GISExercise 2Downstream. png Category: Watershed On Demand: Checked Tooltip: Find Downstream Watersheds Description: This tool selects all watersheds downstream of a user’s click Click ‘Finish’ The new tool is added to your project. Introduction to Arc. GIS Add-ins 15

8. Next you’ll add the toolbar which will contain the two tools. To do

8. Next you’ll add the toolbar which will contain the two tools. To do this go to Project Add New Item. Enter the information as shown in the graphic below. Installed Template: Desktop Add-ins Type: Add-in Command Container Name: toolbar. Watershed. Tools. vb Click ‘Add’ Introduction to Arc. GIS Add-ins 16

9. Enter the information as shown in the graphic below. Add-in Command Bar Type:

9. Enter the information as shown in the graphic below. Add-in Command Bar Type: Toolbar Caption: Watershed Tools Premier Toolbar: Unchecked Items: Select the Upstream and Downstream tools from the combobox Click ‘Finish’ Introduction to Arc. GIS Add-ins 17

10. 11. There is some preexisting code that needs to be added which does

10. 11. There is some preexisting code that needs to be added which does the actual work behind the tools. To add it to the project go to Project Add Existing Item. Add this file: C: tempIntroductionto. Add. Insfor. Arc. GISExercise 2Arc. Map. Code. vb. This custom code also requires that some Arc. Objects references be loaded. Go to Project Add Reference and add the following. NET References (Note: You can click on the Component Name column header to sort the list): ESRI. Arc. GIS. Carto ESRI. Arc. GIS. Display ESRI. Arc. GIS. Editor ESRI. Arc. GIS. Geodatabase ESRI. Arc. GIS. Geometry ESRI. Arc. GIS. Location Introduction to Arc. GIS Add-ins 18

12. You now have all the pieces necessary for your Add-In toolbar. Now add

12. You now have all the pieces necessary for your Add-In toolbar. Now add functionality to the tools. Open the tool. Downstream. vb file and update it to look like the graphic below: Protected Overrides Sub On. Mouse. Down(By. Val arg As ESRI. Arc. GIS. Desktop. Add. Ins. Tool. Mouse. Event. Args) My. Base. On. Mouse. Down(arg) Arc. Map. Code. HU_Find_Downstream(arg. X, arg. Y) End Sub Introduction to Arc. GIS Add-ins 19

13. Do the same for the Upstream tool. Open the tool. Upstream. vb file

13. Do the same for the Upstream tool. Open the tool. Upstream. vb file and update it to look like the graphic below: Protected Overrides Sub On. Mouse. Down(By. Val arg As ESRI. Arc. GIS. Desktop. Add. Ins. Tool. Mouse. Event. Args) My. Base. On. Mouse. Down(arg) Arc. Map. Code. HU_Find_Upstream(arg. X, arg. Y) End Sub Introduction to Arc. GIS Add-ins 20

14. Next save your project. Go to File Save All files and images will

14. Next save your project. Go to File Save All files and images will be saved to the same project directory. 15. Now compile by going to Debug Build Watershed Tools. (If using Visual Studio 2012, go to Build Watershed Tools. ) This will build the Add-In at C: tempIntroductionto. Add. Insfor. Arc. GISExercise 2Watershed. ToolsbinReleaseWatershed. Tools. esri. Add. In and it also installs it to Arcmap’s well-known Add. In folder located at c: Users<username>DocumentsArc. GISAdd. InsDesktop 10. 1 Introduction to Arc. GIS Add-ins 21

16. To test your add-in, open the test MXD located at C: tempIntroductionto. Add.

16. To test your add-in, open the test MXD located at C: tempIntroductionto. Add. Insfor. Arc. GISExercise 2Watersheds. mxd. Go to Customize Toolbars Watershed Tools to open your toolbar. Select the Watershed layer by single clicking on it in the table of contents. Select the Upstream or Downstream tool and click on a watershed. The respective upstream/downstream path for that watershed should become selected. Introduction to Arc. GIS Add-ins 22