I built a model tool which is running perfectly. Because I need to add some more functionalities like filtering, which I can only do with the script, I export the model to script and set the filter which is working fine also. However, when I run the script, it failed and send me a message which i will attach. I guess maybe it is from my tools which is make query table or the SQL statements in the tool which consist inline substitution or something else might be wrong. I will post the script error message, the script and the model. Please kindly help ASAP.
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# single.py
# Created on: 2020-02-08 22:31:43.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: single <Sitename> <Category> <Specie> <Start_Month> <End_Month> <Start_Year> <End_Year> <QueryTable> <QueryTable_Statistics>
# Description:
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
arcpy.env.workspace = "C:\waterfowl\waterfowl\waterfowl.gdb"
arcpy.env.overwriteOutput = True
# Script arguments
Sitename = arcpy.GetParameterAsText(0)
if Sitename == '#' or not Sitename:
Sitename = "Abgrabung Malsch/Durmersheim" # provide a default value if unspecified
Category = arcpy.GetParameterAsText(1)
if Category == '#' or not Category:
Category = "Taucher" # provide a default value if unspecified
Specie = arcpy.GetParameterAsText(2)
if Specie == '#' or not Specie:
Specie = "Haubentaucher" # provide a default value if unspecified
Start_Month = arcpy.GetParameterAsText(3)
if Start_Month == '#' or not Start_Month:
Start_Month = "1" # provide a default value if unspecified
End_Month = arcpy.GetParameterAsText(4)
if End_Month == '#' or not End_Month:
End_Month = "3" # provide a default value if unspecified
Start_Year = arcpy.GetParameterAsText(5)
if Start_Year == '#' or not Start_Year:
Start_Year = "1966" # provide a default value if unspecified
End_Year = arcpy.GetParameterAsText(6)
if End_Year == '#' or not End_Year:
End_Year = "2007" # provide a default value if unspecified
QueryTable = arcpy.GetParameterAsText(7)
if QueryTable == '#' or not QueryTable:
QueryTable = "QueryTable" # provide a default value if unspecified
QueryTable_Statistics = arcpy.GetParameterAsText(8)
if QueryTable_Statistics == '#' or not QueryTable_Statistics:
QueryTable_Statistics = "C:\\waterfowl\\Scratch\\scratch.gdb\\QueryTable_Statistics1" # provide a default value if unspecified
# Local variables:
locationbirdinfo = "locationbirdinfo"
False = "true"
False__2_ = "true"
# Process: Make Query Table
arcpy.MakeQueryTable_management
("locationbirdinfo", QueryTable, "USE_KEY_FIELDS", "", "", "locationbirdinfo.locationinfo_wvz_zaehlgebiete_oag_karlsruhe_Sitename = '%Sitename%' And locationbirdinfo.birdinformation_KAT_Bezeichnung = '%Category%' And locationbirdinfo.birdinformation_ART_Bezeichnung = '%Specie%' And locationbirdinfo.birdinformation_Month_ >= %Start Month% And locationbirdinfo.birdinformation_Month_ <= %End Month% And locationbirdinfo.birdinformation_DAT_Datum >= %Start Year% And locationbirdinfo.birdinformation_DAT_Datum <= %End Year%")
# Process: Summary Statistics
arcpy.Statistics_analysis(QueryTable, QueryTable_Statistics, "locationinfo_wvz_zaehlgebiete_oag_karlsruhe_Sitename MAX;birdinformation_KAT_Bezeichnung MAX;birdinformation_ART_Bezeichnung MAX;birdinformation_Month_ MIN;birdinformation_Month_ MAX;birdinformation_DAT_Datum MIN;birdinformation_DAT_Datum MAX;birdinformation_DAT_Anzahl SUM", "")
I think I will convert it to string using python parser: str(!Datum!), if that makes sense and I hope it works.
so helpful all day and week...Big Thanks.
Hello,
The script below runs perfectly:but the moment I add more statement in line 58:
then I have:
how do I correct this or what could be the right way to do it.
HIGHLY suggest you use string formatting to developing your where expression in line 58. This makes matching single and double quotes and using/not using quotes (for non-string fields in your expression) far easier.
For example:
where = "Sitename = '{}' AND Category = '{}' AND Specie = '{}' AND Datum >= '{}'".format(
Sitename, Category, Specie)
arcpy.Select_analysis(locationbirdinfo, OutputFC, where)