I have exported "Con Tool" script from ModelBuilder. The model has two input parameters one is the DEM and the second is "Long Variable". When I run the model it executes perfectly fine but as I import the script to tool box and assign the variables and type and run them the Python log shows errors. I believe the script is taking the variable name instead of its value.
How do I fix that?
This is the script:
# ---------------------------------------------------------------------------
# conmodelscript.py
# Created on: 2020年07月24日 11:51:39.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: conmodelscript <DEM> <Input_Value>
# Description:
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
# Script arguments
DEM = arcpy.GetParameterAsText(0)
Input_Value = arcpy.GetParameterAsText(1)
# Local variables:
Long = "1"
Output = "C:\\Users\92347円\\Desktop\\test\\output.tif"
# Process: Con
arcpy.gp.Con_sa(DEM, Long, Output, "", "Value<=%Input Value%")
This is the model
This is how I add and run the script
-
2Please Edit the question to contain the error message as text, so that is searchable by others.PolyGeo– PolyGeo ♦2020年07月24日 07:23:25 +00:00Commented Jul 24, 2020 at 7:23
1 Answer 1
Your code has inherited the ModelBuilder inline substitution syntax, which you need to fix to make the code work.
Change this line:
arcpy.gp.Con_sa(DEM, Long, Output, "", "Value<=%Input Value%")
to:
arcpy.gp.Con_sa(DEM, Long, Output, "", "Value <= " + Input_Value)
As you set the variable Input_Value
using GetParameterAsText() it is converting the number into a string so a simple concatenation is all that is required for the where clause in Con().
-
1Thank you so so much. You're a life savior <3 God BlessMudassar Shah– Mudassar Shah2020年07月24日 12:16:11 +00:00Commented Jul 24, 2020 at 12:16
-
2@MudassarShah If this has answered your question please consider up-voting and marking as the answer. See What should I do when someone answers my question?2020年07月24日 21:35:15 +00:00Commented Jul 24, 2020 at 21:35
Explore related questions
See similar questions with these tags.