Python script parameters for Integer not working

1268
4
Jump to solution
09-05-2018 08:37 AM
JustinBridwell2
Occasional Contributor II

 am using a Python library called arcpy_metadata that uses 2 datatype called max_scale and min_scale that take integers:enter image description here

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`.enter image description here

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
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor

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.

View solution in original post

4 Replies
DarrenWiens2
MVP Honored Contributor

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.

JustinBridwell2
Occasional Contributor II

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.

0 Kudos
RichardFairhurst
MVP Honored Contributor

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.

JustinBridwell2
Occasional Contributor II

Yep, that was totally the issue. Rookie mistake.

0 Kudos