Select by attribute in arcpy

07-31-2019 05:29 AM
New Contributor

Good afternoon everybody !

I have an issue with my arpy script. In have a feature layer that contains several farmers and their location in a province. For each province, I would like to take out all the farmers in a single province. The user have to choose this province first and the output would be a table with all the farmer in the choosen Province.

Here is my script for now :

# Load required toolboxes
arcpy.AddToolbox("C:\\Program Files (x86)\\ArcGIS\\Desktop10.3\\ArcToolbox\\Toolboxes\\Data Management Tools.tbx")
arcpy.env.ScratchWorkspace = ("D:\Simon Collet\CG-GEOPROG-2019")

# Local variables:

Exploitants = arcpy.GetParameterAsText(0)  #Feature layer
Expression_selection = arcpy.GetParameterAsText(1)  #SQL expression
Nom_commune =arcpy.GetParameterAsText(2)  #string
Destination_folder =  arcpy.GetParameterAsText(3)  #Folder for the new selection

# Traitement
Exploitants_commune = arcpy.MakeFeatureLayer_management(Exploitants, "Exploitants_comm")
Selection = arcpy.SelectLayerByAttribute_management (Exploitants_commune,"NEW_SELECTION",Expression_selection)
arcpy.CopyFeatures_management(Selection,Destination_folder + "\\" + Nom_commune)

Here is the error message a receive when I execute the script :

Traceback (most recent call last):
  File "D:\Simon Collet\CG-GEOPROG-2019\", line 27, in <module>
    Exploitants_commune = arcpy.MakeFeatureLayer_management(Exploitants, "Exploitants_comm")
  File "c:\program files (x86)\arcgis\desktop10.3\ArcToolbox\Toolboxes\Data Management Tools.tbx", line 6497, in MakeFeatureLayer
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset veyrier does not exist or is not supported
Failed to execute (MakeFeatureLayer).

Failed to execute (ScriptCommune).

Hope someone will be able to help me

Kind regards


0 Kudos
0 Replies