I've created the following field calculation that I'd like to convert to a python script tool:
def blocklow(a, b, c, d): mylist = [a, b, c, d] # create list from input range variables if mylist == [0, 0, 0, 0]: m = 0 else: m = min(i for i in mylist if i > 0) # find minimum value greater than zero if m > 0 and m < 99: return 10 # value for minimum block number between 1-99 elif m == 0: return 0 else: return int(math.floor(m / 100.0)) * 100 # round minimum to lowest hundredesri_field_calculator_splitterblocklow( !LLO!, !LHI!, !RLO!, !RHI!)
The gist of it is there are four address range fields (integer type) and I'm after the lowest numeric value, rounded down to an even hundred, that isn't zero. It works, although I'm sure there is room for improvement.
I'd like to convert this to a script tool. I've done it semi-successfully defining a parameter for the feature class and field to be calculated. However, if add parameters for the input fields of the calculation and then try to reference those in the function, it fails. Also, I'm using the arcpy.CalculateField_management approach but calling a function by as a string kind of sucks. I'm sure there's a more elegant and efficient way.
Here's what the script tool should look like:
I'm really a rookie at best. Any help will be greatly appreciated. I might add, much of the logic I gained from this site. You all are a great resource!
I have several calculations that I'd like to convert to script tools in a toolbox so if I can just get a jump start, that'd be of great help.
Thanks in advance!
أكثر...
def blocklow(a, b, c, d): mylist = [a, b, c, d] # create list from input range variables if mylist == [0, 0, 0, 0]: m = 0 else: m = min(i for i in mylist if i > 0) # find minimum value greater than zero if m > 0 and m < 99: return 10 # value for minimum block number between 1-99 elif m == 0: return 0 else: return int(math.floor(m / 100.0)) * 100 # round minimum to lowest hundredesri_field_calculator_splitterblocklow( !LLO!, !LHI!, !RLO!, !RHI!)
The gist of it is there are four address range fields (integer type) and I'm after the lowest numeric value, rounded down to an even hundred, that isn't zero. It works, although I'm sure there is room for improvement.

I'd like to convert this to a script tool. I've done it semi-successfully defining a parameter for the feature class and field to be calculated. However, if add parameters for the input fields of the calculation and then try to reference those in the function, it fails. Also, I'm using the arcpy.CalculateField_management approach but calling a function by as a string kind of sucks. I'm sure there's a more elegant and efficient way.
Here's what the script tool should look like:

I'm really a rookie at best. Any help will be greatly appreciated. I might add, much of the logic I gained from this site. You all are a great resource!
I have several calculations that I'd like to convert to script tools in a toolbox so if I can just get a jump start, that'd be of great help.
Thanks in advance!
أكثر...