I am making a model with ModelBuilder and my question relates to a smaller part of the model (or like a beginning), where I need to check whether the user input file extension is SHP or GPX and order the model to do different series of geoprocessing for both cases. I didnt find a tool in ModelBuilder that would do exactly what I need, so I guessed that I will need to write a Python script and use script tool in my model.
Could you tell me what I´m doing wrong?
I wrote the following script in PythonWin and saved a .py file, and inserted the script tool into the model. But I don't get the result I expected, as whatever file the input gets, it says either true true for both, or false false for both.
And also how to connect then those "correct" true or false answer values to the next tools?
Is it over a precondition or what exactly?
Here is the script and a few screenshots for better understading. (im a very beginner in scripting....)
Also a link to another topic for reference from where I took the script and tried to adapt it: Checking field type in ModelBuilder using if else?
import arcpy import os input = arcpy.GetParameterAsText(0) name = os.path.basename(input).rstrip(os.path.splitext(input)) extension = os.path.splitext(input).lstrip(".") def CheckExtension(extension): if extension == 'shp': arcpy.SetParameterAsText(1, "true") arcpy.SetParameterAsText(2, "false") elif extension == 'gpx': arcpy.SetParameterAsText(2, "true") arcpy.SetParameterAsText(1, "false") CheckExtension(extension)