# -*- 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 ############################################################################
Solved! Go to Solution.
Spring = arcpy.GetParameterAsText(3) if Spring == '#' or not Spring: Spring = 0.3 # provide a default value if unspecified Spring_float = float(Spring) arcpy.AddMessage(type(Spring))
Spring = arcpy.GetParameterAsText(3) if Spring == '#' or not Spring: Spring = 0.3 # provide a default value if unspecified Spring_float = float(Spring) arcpy.AddMessage(type(Spring))
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
test = arcpy.GetParameter(0) arcpy.AddMessage(type(test))
if type(1.0) == float: print "true"
if str(Tot) == "1.0"
if Tot == "1.0":and nothing worked (went into the else loop and sys.exit() ).
if Tot == 1.0:
import arcpy a = arcpy.GetParameter(0) b = arcpy.GetParameter(1) c = arcpy.GetParameter(2) total = a + b + c arcpy.AddMessage(total) if total == 1.0: arcpy.AddMessage(" all good") else: arcpy.AddMessage(" all not good")