How to add a parameter to a Toolbox GUI to provide a floating numeric value to a script?

1269
6
Jump to solution
03-31-2020 01:42 PM
RobertTrotter
New Contributor III

I running a script using the Toolbox in ArcMap, and the script requires inputs to run.  Most of these inputs such as file names and folders are pretty straight forward.  However, some of the parameters the script uses are simple floating numeric values.  The list of parameter types includes "Any Value", and "Long", but these do not work.  "Long" requires an integer, and "Any Value seems to behave as though it is looking for a data set.

I can simply set the values in the script, but I want to be able to hand off this tool to folks who would use it in the Toolbox, rather than having to access the script directly.  Thanks, and my apologies for what is likely a simple problem!

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

'Double' is the data type you need.

View solution in original post

6 Replies
DanPatterson_Retired
MVP Emeritus

Are you retrieving your parameters in the toolbox using GetParameter or GetParameterAsText or sys.argv ?

You need to check what the toolbox returns which is usually a text representation of the parameter.  

I have used some that you have mentioned and just perform the conversion in the script

x = GetParameterAsText(3)   # parameter is defined as required, input with type Double
try:
    x = float(x)  # ensure inputs can be cast 
.....

with the requisite check for errors on the humanware side.

RobertTrotter
New Contributor III

Hi Dan, this sounds like a great solution, I have been using both the "arcpy.GetParameter" and the "arcpyGetParametersAsText".  The GetParameter function has been useful and simple to use, as long as there is a Data Type that fits the data set well.

I will give this a try and let you know how it goes.

Cheers,


Robert

0 Kudos
DavidPike
MVP Frequent Contributor

'Double' is the data type you need.

DanPatterson_Retired
MVP Emeritus

David Pike‌  in the comments of my post

...input with type Double

RobertTrotter
New Contributor III

This is excellent, thank you!

0 Kudos
DanPatterson_Retired
MVP Emeritus

grief... someone else didn't read the comment line in the sample script

0 Kudos