Converting code from ArcMap to Pro for add-in button. I'm lost on the syntax. Where do I find assembly references to update the ArcMap parts to ArcGIS Pro, etc?
Two button tools. One links to a database with traffic sign supports. The other creates new supports. I may make a third that creates a sign on an existing support. This used to work in ArcMap but does not work with current builds anymore. Any hints are appreciated.
//HyperlinkTSI_Tool
//Optionally modify the values for the message box caption and user prompt
//If necessary enter the correct name of the Support layer and correct field name for SupportID
private const string URL = "F:\APPS\PW\TSI\TSI.accdb ";
private const string USER_PROMPT = "Are you sure you want to hyperlink to the TSI program?";
private const string CAPTION = "Hyperlink to TSI";
private const string LAYER_NAME = "Supports";
private const string SUPPORTID_FIELD = "SupportID";
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
{
//Create envelope for use in spatial filter
ESRI.ArcGIS.ArcMapUI.IMxDocument mxDoc = ArcMap.Document;
ESRI.ArcGIS.Carto.IMap map = mxDoc.FocusMap;
ESRI.ArcGIS.Carto.IActiveView activeView = mxDoc.FocusMap as ESRI.ArcGIS.Carto.IActiveView;
ESRI.ArcGIS.Geometry.IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
ESRI.ArcGIS.Geometry.IEnvelope envelope = point.Envelope;
envelope.Expand(mxDoc.SearchTolerance, mxDoc.SearchTolerance, false);
//Make sure Supports layer is present and create its ILayer instance
ESRI.ArcGIS.Carto.ILayer layer = null;
for (int i = 0; i < map.LayerCount - 1; i++)
{
if (map.get_Layer(i).Name.Equals(LAYER_NAME))
layer = map.get_Layer(i);
}
if (layer == null)
{
System.Windows.Forms.MessageBox.Show(LAYER_NAME + " feature class not found");
return;
}
//Find features within envelope
ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = layer as ESRI.ArcGIS.Carto.IFeatureLayer;
ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;
ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
spatialFilter.Geometry = envelope;
spatialFilter.GeometryField = featureClass.ShapeFieldName;
spatialFilter.set_OutputSpatialReference(featureClass.ShapeFieldName, map.SpatialReference);
spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);
ESRI.ArcGIS.Geodatabase.IFeature feature = featureCursor.NextFeature();
//If the envelope contains a feature, append its support ID to URL and open in default browser
if (feature != null)
{
var result = System.Windows.Forms.MessageBox.Show(USER_PROMPT, CAPTION,
System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
if (result == System.Windows.Forms.DialogResult.Yes)
{
string supportID = feature.get_Value(feature.Fields.FindField(SUPPORTID_FIELD)).ToString();
System.Diagnostics.Process.Start(URL + supportID);
}
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
}
//CreateSupportTool
//Optionally modify the following values for the message box caption and user prompt
private const string USER_PROMPT = "Are you sure you want to create this support?";
private const string CAPTION = "Create Support";
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
{
var result = System.Windows.Forms.MessageBox.Show(USER_PROMPT, CAPTION,
System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question);
if (result == System.Windows.Forms.DialogResult.Yes)
{
//Get coords from MouseEventArgs and insert into TSI Create Support URL parameter string
ESRI.ArcGIS.ArcMapUI.IMxDocument mxDoc = ArcMap.Document;
ESRI.ArcGIS.Carto.IActiveView activeView = mxDoc.FocusMap as ESRI.ArcGIS.Carto.IActiveView;
ESRI.ArcGIS.Geometry.IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y) as ESRI.ArcGIS.Geometry.IPoint;
System.Diagnostics.Process.Start("http://camchdev2k3/tsi/ns.aspx?aid=2&X=" + point.X + "&Y=" + point.Y);
}
}
Solved! Go to Solution.