am using a Python library called arcpy_metadata that uses 2 datatype called max_scale
and min_scale
that take integers:
My code for that is just:
import arcpy, arcpy_metadata as md....min_scale = arcpy.GetParameterAsText(5)max_scale = arcpy.GetParameterAsText(6)....metadata = md.MetadataEditor(file)...metadata. min_scale = min_scale metadata.max_scale = max_scale
I am trying to turn this into a Python script in ArcMap toolbox. An example input for the max and min scale would 5000 and 150000000. Since there is no integer
type and I don't really need decimals, I just entered double
when configuring the parameters for the tool. I also set it as ``optional`.
When I run the tool however, I keep getting the following error. What am I doing wrong here?
RuntimeWarning: Input value must be of type Integer
Solved! Go to Solution.
Using the GetParameterAsText method means that all parameter values are converted to text before being passed to your code. Therefore you have to convert them back to their original type. You need to modify you code to:
min_scale = int(arcpy.GetParameterAsText(5))
max_scale = int(arcpy.GetParameterAsText(6))
However, you may want to add validation to ensure they are valid values (not Null or out of range) before the parameters are converted and passed to the rest of your code.
Your picture shows long (integer), but you say double (float). GetParameterAsText returns a string. This seems to be a data type issue, so I'd start by forcing your parameters into the correct type.
I just got the answer. Feel kinda dumb for missing the whole "GetParameterAsText" part. I just added metadata.max_scale = int(max_scale) and it worked fine.
Using the GetParameterAsText method means that all parameter values are converted to text before being passed to your code. Therefore you have to convert them back to their original type. You need to modify you code to:
min_scale = int(arcpy.GetParameterAsText(5))
max_scale = int(arcpy.GetParameterAsText(6))
However, you may want to add validation to ensure they are valid values (not Null or out of range) before the parameters are converted and passed to the rest of your code.
Yep, that was totally the issue. Rookie mistake.