I cannot enable parameters in a Python toolbox if they are conditionally disabled. My Toolbox code is as follows:
import os, shutil
import arcpy as ap
import arcgis
from arcgis.gis import GIS
global AGOL_TYPES
AGOL_TYPES = ["Feature Collection",
"Feature Service",
"KML",
"KML Collection",
"CSV"
]
class Toolbox(object):
def __init__(self):
self.label = "AGOL Backup"
self.alias = "Backup"
self.tools = [BackupLocal]
class BackupLocal(object):
def __init__(self):
self.label = "Backup"
self.description = "Create local backup of ArcGis Online items."
self.canTunInBackground = False
def getParameterInfo(self):
global AGOL_TYPES
USR = ap.Parameter(
displayName = "AGOL username",
name = "usr",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
PW = ap.Parameter(
displayName = "Password",
name = "psswrd",
datatype = "GPEncryptedString",
parameterType = "Optional",
direction = "Input")
COMPLETE = ap.Parameter(
displayName = "Complete backup",
name = "complete",
datatype = "GPBoolean",
parameterType = "Required",
direction = "Input")
COMPLETE.value = False
OWNER = ap.Parameter(
displayName = "Owner (if different from user)",
name = "owner",
datatype = "GPString",
parameterType = "Optional",
direction = "Input")
OWNER.value = None
DTYPES = ap.Parameter(
displayName = "Data types",
name = "dtypes",
datatype = "GPString",
parameterType = "Optional",
direction = "Input",
multiValue = True)
DTYPES.filter.list = AGOL_TYPES
TAGS = ap.Parameter(
displayName = "Tags",
name = "tags",
datatype = "GPString",
parameterType = "Optional",
direction = "Input",
multiValue = True)
OVERWRITE = ap.Parameter(
displayName = "Overwrite",
name = "overwrite",
datatype = "GPBoolean",
parameterType = "Required",
direction = "Input")
OVERWRITE.value = False
OUT_DIR = ap.Parameter(
displayName = "Backup directory",
name = "out_dir",
datatype = "DEFolder",
parameterType = "Required",
direction = "Output")
OUT_DIR.value = "F:/AGOL_backup"
parameters = [USR, PW, COMPLETE, OWNER, DTYPES, TAGS, OVERWRITE, \
OUT_DIR]
return parameters
def isLicensed(self):
return True
def updateParameters(self, parameters):
[USR, PW, COMPLETE, OWNER, DTYPES, TAGS, OVERWRITE, OUT_DIR] = \
parameters
if COMPLETE and COMPLETE.altered:
OWNER.enabled = False
DTYPES.enabled = False
TAGS.enabled = False
else:
parameters[3].enabled = True
OWNER.enabled = True
DTYPES.enabled = True
TAGS.enabled = True
return
def updateMessages(self, parameters):
return
def execute(self, parameters, messages):
return
I want to show the OWNER, DTYPE and TAG parameters only if COMPLETE is set to False. However, even if the COMPLETE parameter is set to False, these parameters do not show up in the Toolbox interface. Why is that?
As you can see, this happens regardless of whether I call the parameters after assigning them to variables, or directly in the parameter list. Moreover, they do not show up despite the default value for COMPLETE being False, i.e., these parameters are hidden whenever there is just the possibility of their .enabled attribute being set to False.