Select to view content in your preferred language

Limiting FC in input parameter

586
1
10-17-2011 06:42 AM
AprilThorvaldson
Emerging Contributor
Python Script automatically generated by model builder:

# Script arguments
Input_Layer = arcpy.GetParameterAsText(0)
if Input_Layer == '#' or not Input_Layer:
    Input_Layer = "Parcels" # provide a default value if unspecified

I'd like to limit the input fc's to two either 'RollBoundary' or 'Parcels' is there a way to do this?

Please help.  Thanks in advance!
Tags (2)
0 Kudos
1 Reply
ChristopherStorer
Emerging Contributor
I think is the general idea you're looking for.

def ValidateList(in_list, in_value):
    try:
        inputList.index(Input_Layer)
        return 1
    except ValueError:
        print ("Input '" + in_value + "' is invalid.")
        print ("Input should be one of the following:")
        for curItem in inputList:
            print curItem
        return 0

# Script arguments
Input_Layer = 'Test'
if Input_Layer == '#' or not Input_Layer:
    Input_Layer = "Parcels" # provide a default value if unspecified

inputList = ['Parcels', 'RollBoundary']
if ValidateList(inputList, Input_Layer):
    print ("Put execution code here.")


Code will only run if the input value matches your specified list; otherwise, it will print the list of valid values to the user.
0 Kudos