I have written the following script but I cannot manage to create the drop-down list for the variable "select" (select=arcpy.GetParameterAsText(3)). Any suggestions?
# Script arguments
inputRaster = arcpy.GetParameterAsText(0)
cost = arcpy.GetParameterAsText(1)
bene = arcpy.GetParameterAsText(2)
#import Raster
rast = Raster(inputRaster)
#make calculations
rast1 = rast / rast.maximum
rast2 = 1-(rast / rast.maximum)
#Save the output rasters
rast1.save(cost)
rast2.save(bene)
#create a list from rasters
namelist = [rast1,rast2]
select = namelist
#select from a drop-down list
select = arcpy.GetParameterAsText(3)
#Script arguments
weight = arcpy.GetParameterAsText(4)
output = arcpy.GetParameterAsText(5)
#make calculations
selected = Raster(select)
ws = selected * weight
ws.save(output)
I have defined the "select" as "string", is it correct? Also, I have made some edits in validation tab.enter image description here
2 Answers 2
You need to form your namelist
in the actual ToolValidator
class code. This is just used to pass the arguments into your script tool and cannot actually read values from the script you're running unless you imported it.
Actually, the problem was in Validation tab. I Have changed the highlighted line to self.params[1].filter.list = ["COST", "BENEFIT"]
, then I defined the COST and BENEFIT variables in my script and it's run perfectly!
Explore related questions
See similar questions with these tags.
select
in two places, perhaps inadvertently.