Answers:
脚本工具的示例代码,它将具有一个复选框。如果用户将选中一个复选框,则该工具将验证指定数据文件的存在。
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")
在ArcGIS Desktop应用程序中创建新的脚本工具时,请记住要添加布尔数据类型的工具参数。用户运行该工具时,此参数将自动显示为复选框。