What SDK to use to interact with ArcGIS Pro from a .Net WinForms application?

669
4
04-17-2023 02:43 AM
ChrisNightingale
New Contributor II

Hi all,

I'm looking for some guidance as to where to start looking for information on how to interact with ArcGIS Pro from our .WinForms Net application as there seems to be a lot of different SDKs but not sure where to start.

What I'm looking to do is implement the same functionality in ArcGIS Pro as we currently do with ArcMap 10.8.2.

Here is a summary of what we currently do in ArcMap 10.8.2:

  • We launch ArcMap and get it to open a custom .mxd file which contains settings for a number of menu items and a toolbar we have embedded in ArcMap via the use of some c# assemblies that we created which make use of the ESRI ArcGIS framework (e.g. ESRI.ArcGIS.Framework.dll)
  • We also send geospatial information from our .Net app (via a temporary file) which it then displays on a Data Layer using custom icons
  • The toolbar has a number of commands (which derive from ESRI.ArcGIS.ADF.BaseClasses.BaseTool) which are used to perform actions on features on the map data layer.
  • The menu items (which derive from ESRI.ArcGIS.ADF.BaseClasses.BaseCommand) signal back to our application with the selected features via the use of a temporary file (our app monitors changes to the file)


So basically I'm looking to interact with ArcGIS Pro from our app and maybe hoping there is a better way of communicating than through the use of temporary files.

The closest thing I have found so far is the "ArcGIS Pro SDK for .NET" so maybe someone could advise whether this is the best way achieve the interaction between our app and ArcGIS Pro.

Thanks,

Chris

0 Kudos
4 Replies
KrisCulin
Occasional Contributor

Hi Chris,

Everything you have described in your list CAN be done in ArcGIS Pro using the SDK via an AddIn.

The question is whether you will target ArcGIS Pro 2.x or 3.x.  I can't tell you what to use but I do recommend that you target ArcGIS Pro 3.  The documentation is current for that version and finding older documentation could be problematic.

I recommend that you read through the sdk wiki on GitHub at Home · Esri/arcgis-pro-sdk Wiki (github.com).  It is well written and has lots and lots of details.  They also have a set of samples you can clone from GitHub.  I made extensive use of the samples to understand how things work.

Creating tools (for layout), buttons for the ribbon, etc., is very easy in ArcGIS Pro.  I think you will enjoy using the SDK.

Since you mention Windows Forms, I do need to point out that AGP3 targets .NET6.  AGP2 targets .NET Framework 4.8.  Don't let that discourage you though.  It doesn't sound like your code is super extensive so getting it .NET 6 read should not be all that difficult (I could be wrong - just making an assumption here - and comparing to my own very extensive product line that took months to move to net6).  Again, don't get discouraged.

Microsoft has really good documentation on the migration from .NET Framework to .NET 5+.  Check this out - Migrate a Windows Forms app to .NET 5 - Windows Forms .NET | Microsoft Learn.  Although it says .NET 5, it does apply to .NET 5+.

If your code base is 100% C# then the migration should go very, very smoothly.  If you have 3rd party user controls, you'll need to upgrade to net6 compatible versions.  At this point, all the major vendors have net6 compatible controls.

Good luck and have some fun.

Kris

ChrisNightingale
New Contributor II

Hi Kris,

Many thanks for the info - that's really useful and at least suggests I'm heading in the right direction.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

i would convert the custom mxd into an ArcGIS Pro project file (.aprx).  To start ArcGIS Pro i would simply start a new process: Process.Start Method (System.Diagnostics) | Microsoft Learn by using the ArcGIS Pro executable followed by the .aprx project file name.   This will open ArcGIS Pro with your .aprx custom project.  To get path of the ArcGIS Pro executable you have to look at the ArcGIS Pro installation path in the registry (programmatically), the following community sample has the code to retrieve the installation location: arcgis-pro-sdk-community-samples/Program.cs at master · Esri/arcgis-pro-sdk-community-samples (githu...

On the ArcGIS Pro side i would install a custom ArcGIS add-in with the following 'autoLoad' setting changed in the config.daml (this will cause the add-in to load at startup of Pro and not be JIT loaded):

<insertModule id="..." className="Module1" autoLoad="true" ...>
   

For interprocess communication (IPC) i would use 'Anonymous Pipes'  AnonymousPipeServerStream Class (System.IO.Pipes) | Microsoft Learn

Needless to say there is the client equivalent: AnonymousPipeClientStream Class (System.IO.Pipes) | Microsoft Learn

To exchange data i would write the data into a shared CSV file and use the IPC to inform the add-in of any new data files and the add-in can take care of loading / displaying the data.  ArcGIS Pro add-ins are multi-threaded extensions and are well suited to support IPC.

ChrisNightingale
New Contributor II

Hi Wolf,

That's really useful as I was looking for an equivalent of what we had been doing before which was basically this:

  • Creating a `AppROTClass` object to find a running copy of ArcMAP (and if found casting to `IMxApplication`)
  • If not found launching ArcMap via the `MxDocumentClass` and opening up our template .mdx file.
  • Finding a suitable data layer and then populating it with data from a file we created elsewhere.

So from the sounds of things, there is no direct replacement for the above and the best way to achieve it is as you described.

And it seems like the "Anonymous Pipe" method for comms between ArcGIS Pro and our app would be the best way of getting data back to our application (as sometimes we want to select features on the map and tell our app to do something with that information e.g. open up some address records)

 

0 Kudos