AnsweredAssumed Answered

Problem with script tool parameters (parameter comes in as string when I want float)

Question asked by davisam1 on Jun 10, 2014
Latest reply on Jun 10, 2014 by davisam1
Hi!

I have a python script that runs fine stand alone but when I try to make it GUI based by adding it to a toolbox as a script I get errors which I believe are related to how I am setting the parameters.

I have three values that I need to be set as a real number with a decimal but they keep coming in as string.

In ArcGIS toolbox, under properties of the model, and the parameters tab, I set those three parameter types to Double (I have also tried String but that doesn't work either).

then in python, that part of the code looks like this:
# -*- coding: utf-8 -*-  ############################################################################  import sys # Import arcpy module import arcpy #from arcpy import env  # Set this to False once testing is complete arcpy.env.overwriteOutput = True  ############################################################################     # Script arguments  # user defined weights for importance of up to three floral seasons Spring = float(arcpy.GetParameter(3)) arcpy.AddMessage("Floral Weight #1 is equal to: " + str(Spring)) if Spring == '#' or not Spring:     Spring = 0.3 # provide a default value if unspecified check1 = arcpy.Parameter(Spring) arcpy.AddMessage("Data type is: " + str(check1.datatype))  Summer = float(arcpy.GetParameter(4)) if Summer == '#' or not Summer:     Summer = 0.6 # provide a default value if unspecified      Fall = float(arcpy.GetParameter(5)) if Fall == '#' or not Fall:     Fall = 0.1 # provide a default value if unspecified      Tot = Spring + Summer + Fall arcpy.AddMessage("Floral Weights are equal to: " + str(Tot)) if Tot == 1:     arcpy.AddMessage("Sum of floral weights is equal to: " + str(Tot)) else:     arcpy.AddError("The sum of floral weights must equal to one.")     sys.exit() # exit out of model if weights don't add up to 1  ############################################################################


I've tried GetParameter and GetParameterAsText but the value always seems to be coming in as a string.

I know this is probably something very basic but I just can't figure it out.

I'm using ArcGIS 10.2.

Thank you in advance for any assistance.

Sincerely,
Amelie

Outcomes