4

I've been working with ESRI Python toolboxes for a while but I'm still having difficulties setting an input parameter as a "DEWorkspace" and using the parameter filter to make it so only file geodatabases are visible to the end user when entering parameters.

I'm using 10.5 and this is the ESRI documentation

    param0 = arcpy.Parameter(
    displayName="Input Workspace",
    name="in_workspace",
    datatype="DEWorkspace",
    parameterType="Required",
    direction="Input")

# Set the filter to accept only local (personal or file) geodatabases
    param0.filter.list = ["Local Database"]
    params = [param0]
    return params

The problem I'm encountering is that this filter doesn't seem to actually limit what the end user can see or enter as parameter. For example when they navigate to provide a file geodatabse the dialog allows them to see and enter .lyr files. enter image description here

I'm assuming that you should be able to limit what the end user can see and enter when it comes to workspaces?

1

It seems that it only occurs with the combination of *.lyr files and "Local Database" filter, but other types of files are filtered out as expected. The filter works fine for the other workspace type options.

As a workaround, you can check by yourself that the input value is indeed a file geodatabase and then use the internal validation of the tool to add a warning or error message:

def updateMessages(self, parameters):

    workspace = parameters[0].valueAsText

    if not os.path.isdir(workspace) or not os.path.splitext(workspace)[-1] == ".gdb":
        parameters[0].setWarningMessage("This is not a File Geodatabase")

    return

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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