In the python script tool I am programming (see code below), I am using a simple boolean checkbox to enable/disable certain parameters in the script GUI. However, even though the parameters get disabled correctly (greyed out, see screen capture), when I add points to my featureSet parameter interactively and click on OK to run, I receive error 000735 that the parameters I disabled are "required", impeding the run.
Is there any workaround to having to set inTable, X_field, and Y_field as "Optional"? In other words, can those 3 appear as Required and be correctly disabled without impeding script execution?
Code:
# Import all necessary module dependencies
import arcpy
import os
import sys
arcpy.env.overwriteOutput = True
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(3857)
def DrawSystems():
# Local variable:
out_layer = "Systems_lyr"
# Get the value of the input parameter
isChecked = arcpy.GetParameter(0)
inTable = arcpy.GetParameterAsText(1)
X_field = arcpy.GetParameterAsText(2)
Y_field = arcpy.GetParameterAsText(3)
inFeatureSet = arcpy.GetParameterAsText(4)
arcpy.SetProgressorLabel('Creating System Components ...')
arcpy.AddMessage('Creating System Components ...')
if isChecked == False:
if inTable or inTable != "#":
try:
# Process: Make XY Event Layer (temporary)
arcpy.MakeXYEventLayer_management(table=inTable,
in_x_field=X_field, in_y_field=Y_field,
out_layer=out_layer)
except Exception:
e = sys.exc_info()[1]
arcpy.AddError('An error occurred: {}'.format(e.args[0]))
else:
if inFeatureSet or inFeatureSet != "#":
try:
# Process: Make Feature Layer (temporary)
arcpy.MakeFeatureLayer_management(in_features=inFeatureSet, out_layer=out_layer)
except Exception:
e = sys.exc_info()[1]
arcpy.AddError('An error occurred: {}'.format(e.args[0])) # Process: Create Feature Class from Feature Layer
#### Create Feature Class & Add Coordinates ####
try:
# Process: Copy Feature Class
outSystems_fc = os.path.join(arcpy.env.scratchGDB, "Systems")
outFC = arcpy.CopyFeatures_management(out_layer, outSystems_fc)
arcpy.SetProgressorLabel('Adding XY Coordinates ...')
arcpy.AddMessage('Adding XY Coordinates ...')
# Process: Add Coordinates
arcpy.AddXY_management(outFC)
except:
arcpy.AddIDMessage("ERROR", 930)
#### Set Parameters ####
arcpy.SetParameter(5, outFC)
if __name__ == '__main__':
DrawSystems()
You could try to use a python tool box and if isChecked == False: then parameterType = "Optional"
Customizing tool behavior in a Python toolbox—Help | ArcGIS for Desktop
Wes, I thought that parameterType is a read-only property...so that would not work if that is the case.