1

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

1
  • I think you should collect all your GetParameterAsText functions together at the top of your script. At the moment you are setting select in two places, perhaps inadvertently.
    – PolyGeo
    Jul 1, 2016 at 1:21

2 Answers 2

1

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.

0
0

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.