Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2019: A C# Odyssey, Migrating Python Add-Ins fr...

2019: A C# Odyssey, Migrating Python Add-Ins from ArcMap to ArcGIS Pro

By John Phillips, Matt Washburn, TxDOT

More Decks by Texas Natural Resources Information System

Other Decks in Technology

Transcript

  1. 2019 Texas GIS Forum October 23, 2019 Date 2019: A

    Odyssey Migrating Python Add-Ins from ArcMap to ArcGIS Pro John Phillips Matt Washburn
  2. 2019 Texas GIS Forum October 23, 2019 Roadmap 2 §

    BP (Before Pro) – Why Pro? – Python Add-Ins – Choosing the Right Tools § The Journey – Learning C# – Dev Summit – Practice, Collaboration and Testing § Your Turn: Getting Started § Scenarios – Simple: Launch a native GP tool using C# – Hybrid: Launch a custom python script and run in command shell – Advanced: Completely rewrite tool in C# – C# Wiz: Customize the UI using WPF (dock panes!) § Lessons Learned
  3. 2019 Texas GIS Forum October 23, 2019 BP (Before Pro)

    Time Period – Why Pro? 3 § Geospatial Roadway Inventory Database (G.R.I.D) – Custom database application – Roadway Geometry and assets § Custom and built-in Editing, ETL and Linear Referencing Tools – Set From/To Measures – Identify Route Locations
  4. 2019 Texas GIS Forum October 23, 2019 BP (Before Pro)

    Time Period – Why Pro? 4 § End of ArcMap Era in sight § ArcGIS Pro – Multi-threaded/64-bit – C# .NET architecture – Dark Mode!! § Development of tools not on Pro roadmap or locked behind extension (Roads and Highways)
  5. 2019 Texas GIS Forum October 23, 2019 BP (Before Pro)

    Time Period – Python Add-Ins 5 § Python Add-In Wizard § Mostly limited to launching GP Tools, external python scripts § Tried to write LRS tools for Pro in python, but results weren’t consistent
  6. 2019 Texas GIS Forum October 23, 2019 6 § Customization

    Patterns: – Configure UI through settings, and workflows through Tasks (Backstage Tab, limited, no code) – Automate using geoprocessing and Python. (arcpy and arcgis API) – Extend with your own custom tools and solutions using the Pro SDK. (C# Add-Ins) – https://github.com/esri/arcgis-pro- sdk/wiki/ProConcepts-Migrating-to-ArcGIS-Pro § C# Patterns – Custom Add-Ins – Managed Configurations – Tons of options (dropdowns, context menus, dockpanes, map tools, sounds, etc) BP (Before Pro) Time Period – Choosing the Right Tools
  7. 2019 Texas GIS Forum October 23, 2019 The Journey –

    Learning C# 7 § Used Esri credits to bring out teachers – 2-Day ArcGIS Pro Course – 4-Day Extending ArcGIS Pro with Addins (EAPA) Course § Beginner/Intermediate knowledge of C# recommended for EAPA § ‘Firehose’ of information/Big learning curve § Previous programming experience helps! § After the C# course we were developing perfect add-ins with no problems!***
  8. 2019 Texas GIS Forum October 23, 2019 BP (Before Pro)

    Time Period 9 I’m sorry John, I’m afraid I can’t do that
  9. 2019 Texas GIS Forum October 23, 2019 The Journey –

    Dev Summit 10 § Esri Developer Summit – Developers of API teach sessions – One on one questions and feedback – Dodgeball!
  10. 2019 Texas GIS Forum October 23, 2019 The Journey –

    Practice, Collaboration and Testing 11 § Weekly learning sessions working through guide together § Esri Documentation – API/SDK Page – Community Samples – Pro Snippets – GeoNet § Testing team and bug fixes § Practice!
  11. 2019 Texas GIS Forum October 23, 2019 Your Turn: Getting

    Started 12 § Visual Studio 2017 (Community Edition is free) § ArcGIS Pro (Not free) § ArcGIS Pro SDK (Software Development Kit) – Downloaded through Visual Studio – Inserts code templates – IntelliSense
  12. 2019 Texas GIS Forum October 23, 2019 Four Scenarios §

    “Simple”: Launch a native GP tool using C# § Hybrid: Launch a custom python script and run in command shell § Advanced: Completely rewrite tool in C# § C# Wiz: Customize the UI using WPF 13
  13. 2019 Texas GIS Forum October 23, 2019 “Simple” Scenario §

    Want to run GP tool with one click § Useful for quick, commonly used operations § Control over where button is placed (context menu) § Call using C# § Example: Calculate Geometry 14
  14. 2019 Texas GIS Forum October 23, 2019 “Simple” Scenario §

    Create new VS project and add button using Pro SDK § Set path to GP tool using its alias § Set arguments based on Python documentation § Construct value array and pass those args to ExecuteToolAsync() 15
  15. 2019 Texas GIS Forum October 23, 2019 “Simple” Scenario §

    Add reference to button in the DAML (markup file) § Controls where the button is located in the application § Default is on “Add In” tab along top ribbon § Customized to add to specific context menu § Can add anywhere 16
  16. 2019 Texas GIS Forum October 23, 2019 Hybrid Scenario §

    Want to launch custom Python script with button § Pass args to script and run externally in command shell § Useful when working with legacy (i.e. 2.x) Python scripts § Allows migration to Pro without rewriting entire codebase § Example: Hello World 17
  17. 2019 Texas GIS Forum October 23, 2019 Hybrid Scenario 19

    § Script launches, accepting input from user § Passes input as args in script § Could be OIDs, map selection, attributes, etc. § Useful for getting up and running quickly § Familiar Python prog patterns § Use existing scripts
  18. 2019 Texas GIS Forum October 23, 2019 Advanced Scenario §

    Need to completely rewrite Python script in C# § Not only is syntax different, not always a corresponding method § C# more verbose, many, many more ways to do one thing § Example: Jump To Google/Jump To Streetview 20
  19. 2019 Texas GIS Forum October 23, 2019 Advanced Scenario §

    Same logic, syntax and methods different § Save time/sanity by reading documentation FIRST! § Ex: Camera property accesses Scale § Use original script as pseudocode 21
  20. 2019 Texas GIS Forum October 23, 2019 C# Wiz §

    Fully customize UI with MVVM(Model View-View Model) patterns – Dockpanes – Managed Configurations – CIM Editing § Example: Dockpane! 22
  21. 2019 Texas GIS Forum October 23, 2019 C# Wiz §

    Create Dockpane using SDK template § Declare in DAML § Design layout and bind to data with XAML § Add logic in C# files 23
  22. 2019 Texas GIS Forum October 23, 2019 Lessons Learned 24

    § Versioned Releases § Log Bugs – Spreadsheet, Trello, Bug Software § Testing – Test scripts (learn from our mistakes) § Try/Catch Statements – Very important to prevent frequent crashes § Breakpoints/Debugging/Object Explorer § Communication/Collaboration! (GitHub)