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", "")
Results was not created...I can't find the output in the folder but was created in my result pane as successful...but could not add to display on the TOC.
is it in the geodatabase then?
No. Not in the geodatabase also
I upgraded to 2.5 now, I think like you mentioned earlier..The problem is the join table and the underscore but which I will work and try to do without the underscore.
If your model is running perfectly, why not call it from a python script that has the parameter validation (I assume that is what you mean by "filtering") set up?
You can call a ModelBuilder tool from Python:
ImportToolbox—Help | Documentation
ModelBuilder itself also has some built in parameter validation that handle certain simple cases, for example only allow a point feature input instead of all kinds of feature classes:
That will change the entire script right. Have you seen my script, if not should i post it for you to see.
My point is you can call a model tool from Python, so you don't need to export the model at all.
ok...I will do that. Thanks.
Hello , I have done alot of correction and am still faced with errors....am stressed on this for 2weeks on more...the new error is this: initially the python export was like this: it gave the error and changed some change some few things, and same error...is there something wrong somewhere on my system..please help.
You have a double quote at the end of the selection on the first one and a = f" for the second one