Using Drawing Tools in Python

5847
6
03-03-2015 08:32 AM
DavidGranata
New Contributor II

I am trying to make a user friendly interface needing to capture an area of interest boundary to use in selecting layer records to be processed with Python.  I would like to imitate the interactive GUI capability of simply drawing a graphic rectangle on the map and use the "select by graphic" to select the layer records to process.  Is there a way to access these functions or is there a way to emulate this simple user interface in Python?

0 Kudos
6 Replies
JakeSkinner
Esri Esteemed Contributor

Hi David,

Take a look at the python add-in example here.  You will just need to update the code slightly to perform a 'Select by Location'.

0 Kudos
DavidGranata
New Contributor II

Jake,

Thank you for the information.

Is this only available with the Addin?  I am developing a Script tool specifically.  I am new to Python and have been working with ESRI Tech Support for assistance and was lead in the direction of developing a Script tool as being a bit less complicated to create.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Yes, you can do this by using the following code:

import arcpy

graphic = arcpy.GetParameterAsText(0)

arcpy.MakeFeatureLayer_management(graphic, "lyr")
arcpy.SelectLayerByLocation_management(arcpy.GetParameterAsText(1), "INTERSECT", "lyr")
arcpy.RefreshActiveView()

You will then want to add this script to a toolbox.  See the section 'Adding Script Tools' here.  After you add the script, right-click on the Script tool > Properties > Parameters tab.  You will want to set up two parameters:

screen1.png

For the first parameter, select a polygon feature class for the 'Schema' in the Parameter Properties.  The tool should then be ready to use.

0 Kudos
DavidGranata
New Contributor II

Hi Jake,

Thank you for providing information and education.

That is the point where I currently am at with my Script tool.  You have to define the schema to use which is the polygon editing.  The user interaction at this point is a polygon editing tool.  If you use the "rectangle" default the user interface is to make 3 clicks, not like the simple graphic rectangle draw click and drag a rectangle - very user friendly.

This is the meat of my inquiry.  A user needs a little education on how to "digitize" a rectangle.  The graphic rectangle is so intuitive and user friendly needing no education.  I would like to improve the user experience to make it as simple as the interactive graphic draw capability (if it were open to Python to use).

0 Kudos
JakeSkinner
Esri Esteemed Contributor

I don't believe you can set the default tool for a script tool.  However, you can use a rectangle for the shape property of a python add-in tool.  Developing a python add-in will be a little more complex, but it will accomplish the user experience you are looking for.

0 Kudos
DavidGranata
New Contributor II

Thank you Jake,

It would be so much easier if Python had access to the "Graphic Draw tools" and the "Select by Graphic" in the interactive user interface.

0 Kudos