1

I am using ArcMap 10.5, but help pages I am referring are the same as in 10.7.

I am trying to make a GP tool within Python toolbox with kind of selection input: user selects features in ArcMap interactively.

I was reading Using the interactive feature and record input controls and found that it's possible for GP tool to have such kind of parameter. Quote: "The interactive feature input control gives you two methods for inputting features to a tool—either by clicking on a map display or by providing an existing dataset."

OK, so I checked what parameter types I can create here: Defining parameter data types in a Python toolbox and it seems that Feature Set (GPFeatureRecordSetLayer) is what I am looking for as description says: "Interactive features that draw the features when the tool is run.".

Here is my magic tool, but I do not see any way to "enter features interactively":

class AttachTool(object): def __init__(self): """Define the tool (tool name is the name of the class).""" self.label = "Add attachments" self.description = "Adds the same file as attachment to multiple selected features" self.canRunInBackground = False def isLicensed(self): """Set whether tool is licensed to execute.""" return True def getParameterInfo(self): """Define parameter definitions""" paramInputFeatures = arcpy.Parameter( displayName="Input Features", name="in_feature_set", datatype="GPFeatureRecordSetLayer", # Interactive features that draw the features when the tool is run parameterType="Required", direction="Input", multiValue = True) paramInputFile = arcpy.Parameter( displayName="File to attach", name="in_file", datatype="DEFile", parameterType="Required", direction="Input") return [paramInputFeatures, paramInputFile] def updateParameters(self, parameters): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.""" return def updateMessages(self, parameters): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" return def execute(self, parameters, messages): """The source code of the tool.""" arcpy.AddMessage('Just pretending to do something...') return 

Input field looks like this and I don't see how I should select features... enter image description here

PS. Copy on GeoNet: https://community.esri.com/thread/243774-arcpyparameter-how-to-create-the-interactive-feature-input-control

1 Answer 1

2

The ArcGIS Pro topic for Python toolbox parameters looks to have a bit more information. Find the section: About Feature and Record Sets The information you need is:

The symbology and schema (attributes and geometry type) can be set for the Feature Set and Record Set control by setting the parameter's value property to a feature class, table, or layer file (.lyrx).

By providing the parameter value to an item with both schema and symbology (ie. a LYR file in ArcMap), the tool will open allowing you to draw the particular features. eg.

param0.value = os.path.join(os.path.dirname(__file__),'Fire_Station.lyrx') 
2
  • Yes, there is more info here. It seems that I misunderstand what "interactive input" means. It is not the selection of existing features, but features that user adds (I suppose) in edit session?.. Commented Nov 15, 2019 at 13:47
  • 1
    You can use interactively drawn features to perform a selection. The interactive draw of a polygon can be passed to Select by Location to do this. Commented Nov 15, 2019 at 14:48

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.