[GIS] Creating checkbox parameter in Python script tool for ArcGIS Desktop

arcpypython-script-tool

I am working on creating an ArcGIS tool from a Python script I am writing. I am wondering if it is possible to have a checkbox parameter.

I want to have a parameter where the user selects a feature class, then from the feature class the user will choose the field for the upper most layer in their model, then I want the user to be able to choose what layers they want the script to run on with a checkbox structure derived from the upper most layer field.

Is this possible with python, and ArcGIS Desktop?

Best Answer

A sample code for a script tool which will have a single check box. If a check box will be checked by a user, the tool will verify existance of a specified data file.

import arcpy
input_fc = r'C:\GIS\Temp\data_shp.shp'

    #getting the input parameter - will become a tool parameter in ArcGIS of Boolean type
    ischecked = arcpy.GetParameterAsText(0)

    #Important to convert the check box value to a string first.
    #Should be 'true' with the small case for 't',
    #not the 'True' as shown in the Python window in ArcGIS
    if str(ischecked) == 'true':
        arcpy.AddMessage("The check box was checked")
        result = arcpy.Exists(input_fc)
        #to return 'True' or 'False' depending on whether the data file exists
        #since it is a Boolean, important to convert it to a string
        arcpy.AddMessage(str(result))

    else: #in this case, the check box value is 'false', user did not check the box
        arcpy.AddMessage("The check box was not checked")

Remember to add a tool parameter of Boolean data type when creating a new script tool in ArcGIS Desktop application. This parameter will be automatically shown as a check box when user runs the tool.

enter image description here