13

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?

2 Answers 2

15

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

0
7

To see how to get a checkbox onto the dialog of a Python script tool try using some test code like this:

inputString = arcpy.GetParameterAsText(0)
inputBoolean = arcpy.GetParameterAsText(1)

arcpy.AddMessage("String set to " + inputString)
arcpy.AddMessage("Boolean set to " + str(inputBoolean))

Then when you add this script as a tool you will need two Parameters, the first of Data Type String and the second of Data Type Boolean.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.