I'm still bitter with ESRI for not bringing Python Add-Ins over to Pro.. I have never coded in C#/.NET and know very little about ArcObjects. My Python skills I consider to be strong, not just scripting but app development, so I think I can pick up on the .NET SDK, though I am reluctant to get into this rabbit hole. I have VS and the SDK up and running, went through some tutorials, just looking for some guidance on a specific solution here.
A while back I created a little ArcMap Add-In, just a single toolbar button that will open Google Street View in your default browser when the user clicks a location on the map. I'd like to deploy a button like this in Pro, but after searching and searching for 'C# open a web page on click event' all I was coming up with was ASP.NET stuff and I have zero knowledge on any of this stuff lol! I was basically looking for a one liner to add into the onClick event of my button.cs code to just open Google.com to start with.
Below is the Python Add-In code that accomplishes this, and I am not looking for anyone to code this entirely for me, but maybe some suggestions, guidance, resources, etc. All this does is grab the coordinates from where the user clicks and feeds that into a url to open street view.
"""Implementation for StreetView_addin.tool (Tool)"""
self.enabled = True
self.cursor = 3 # cross hair cursor
def onMouseDownMap(self, x, y, button, shift):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)
sr_df = df.spatialReference
pt = arcpy.Point(x,y)
pt_geom = arcpy.PointGeometry(pt, sr_df)
new_pt_geom = pt_geom.projectAs("WGS 1984")
new_pt = new_pt_geom.firstPoint
new_X = new_pt.X
new_Y = new_pt.Y
## message = "Projected: " + str(x) + ", " + str(y) + " Geographic: " + str(new_X) + ", " + str(new_Y)
## pythonaddins.MessageBox(message, "Coordinates")
maps_url = "https://maps.google.com/maps?q=&layer=c&cbll=" + str(new_Y) + "," + str(new_X)
Solved! Go to Solution.
Try creating a MapTool instead of a button. I had the exact same problem and found a solution here:
One thing to keep in mind is that you need a way to deactivate the tool after you click on the map. Adding this line at the end of the QueuedTask works for me:
Based on this, I was also able to recreate a python addin that opens Google Maps at the MapView center and zoom level.
Hope this helps!
There are a few ways to accomplish this with .NET. One suggestion is posted here on stackoverflow.
Code snippet to open a url in a Pro button OnClick method:
internal class OpenURL : Button
protected override void OnClick()
You can use string interpolation to pass in the points to the string.
Hi Uma, thanks for the reply! So when I try just that line and click the button in Pro it grays out and nothing happens. I tried a variety of the suggestions on the stackoverflow site and it's the same behavior, button grays out on first click and no browser window opens. The final suggestion seemed promising but did not work. What is commented out is what I tried just before that.
internal class OpenGoogle : Button
protected override void OnClick()
var processes = Process.GetProcessesByName("Chrome");
var path = processes.FirstOrDefault()?.MainModule?.FileName;
string url = "http://google.com";
//System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
//myProcess.StartInfo.UseShellExecute = true;
//myProcess.StartInfo.FileName = url;
One of the main reasons this happens is if the namespace of the button class (StreetViewButton from your code snippet above) doesn't match the namespace defined in your config.daml or in your add-ins settings.
Please check out this topic to see if this could be an issue: ProGuide Diagnosing ArcGIS Pro Add ins · Esri/arcgis-pro-sdk Wiki · GitHub
The config was auto generated, and I have not touched it since adding the button to the project. Looks like it added _Module, _Group1, _Button1 to the namespace name. Do these all need to be identical?
In this screenshot, I see one issue: In the button element defined in the Config.daml, notice that the className attribute is set to Button1. But in the code snippet you shared above your button class is actually OpenGoogle. So try changing that in the config.daml - to match your button class.