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

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 1, 2016 at 1:17
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. Commented 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.

answered Jul 1, 2016 at 1:20
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!

crmackey
8,54420 silver badges33 bronze badges
answered Jul 2, 2016 at 9:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.