Select to view content in your preferred language

Can you spare a code snippet to select feature?

638
1
07-03-2019 09:40 AM
TomMagdaleno
Frequent Contributor

Hi All,

  I am working with traffic sign supports.  I need to make a button to select a support from the map.  I don't know how to code, but I've had good luck modifying other peoples code that is similar.  I've looked all through the site and can't figure out how to make a button that allows the user to select by either drawing an envelope or clicking the point.  Has the name changed?  It should only select one point at a time.  May I borrow some code?

The button needs to allow the user to drag an envelope or click on a point in a "Supports" feature class

(Does the code need to verify the feature class exists in the project?)

Find the SupportID field in that feature class

Feed that SupportID to another piece of code that will open a specific record in a form in Microsoft Access.  (I have a python code for this piece.  Will that even work?)

If anyone has a code snippet that does something similar I would be very grateful.    

0 Kudos
1 Reply
MatthewDriscoll
MVP Alum

https://github.com/Esri/arcgis-pro-sdk

Download the examples.  Map tool is the one you want.  I believe under Map Exploration there is an actual map tool select example. 

To select only one I usually just add a message box

if (_selectedFeature.SelectionCount > 1)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Select One Point Only", "Try Again");
                return;

            }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

For linking your python code I have only found using a Python Toolbox works for me in the Pro SDK, not a stand alone script.  Not saying it cannot be done.  Put the Toolbox in the solution and call it by doing something like below.  This is pretty much exactly the same as in the documentation for the SDK.

public async Task<IGPResult> ExecuteModel()
        {

            var progDlg = new ProgressDialog("Running Geoprocessing Tool", "Cancel");
            progDlg.Show();

            var progSrc = new CancelableProgressorSource(progDlg);


            var pathPython = System.IO.Path.GetDirectoryName((new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath);
            pathPython = Uri.UnescapeDataString(pathPython);
            System.Diagnostics.Debug.WriteLine(pathPython);


            var tool_path = System.IO.Path.Combine(pathPython, @"ToolboxName.pyt\Tool");

            var parameters = Geoprocessing.MakeValueArray();

            IGPResult gp_result = await Geoprocessing.ExecuteToolAsync(tool_path, parameters, null, new CancelableProgressorSource(progDlg).Progressor);

            Geoprocessing.ShowMessageBox(gp_result.Messages, tool_path, gp_result.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);

            return gp_result;

        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I highly recommend the Extending ArcGIS Pro with Add-Ins instructor-led course.  I only knew Python before I took it and was able to produce the Pro C# SDK Add-ins in no time at all.