3

When adding a python script tool to ArcToolbox, you can specify valid input types using the dropdown "Data Types" on the parameters tab in the tool properties.

enter image description here

In Python Toolboxes you can set these input types using the datatype property in the Parameters function. eg datatype = "DEWorkspace"

def getParameterInfo(self):
    param0 = arcpy.Parameter(
        displayName="Input workspace",
        name="in_workspace",
        datatype="DEWorkspace",
        parameterType="Required",
        direction="Input") 

Both of these options seem to work OK when setting up the script.

Unfortunately, while in the script tool properties I have the option of a data type called "Workspace and Feature Dataset" (seen in the screenshot above), this option doesn't exist as a data type in Python Toolboxes. So I found that it is possible to set multiple valid data types, called "Composite Data types." eg datatype = ["DEWorkspace","DEFeatureDataset"]

def getParameterInfo(self):
    param0 = arcpy.Parameter(
        displayName="Input Raster Dataset",
        name="in_rasterdataset",
        datatype=["DERasterDataset", "DERasterCatalog"],
        parameterType="Required",
        direction="Input") 

However, I have found that any time I set a composite data type in my python toolboxes, there is no restriction enforced, so I can add any input I want and run the tool (which will then fail as it's received the wrong input data type). If I have only one data type specified I am restricted to adding or browsing to that one data type, but if I have two or more data types the restriction disappears altogether. In the screenshot below you can see an image and a layer file, neither of which fits the definition of Workspace or Feature Dataset.

enter image description here

So what am I doing wrong when defining my composite data types? How can I set my Python Toolbox tool to allow both Workspaces and Feature Datasets, but not allow other types of inputs?

My getParameterInfo function:

def getParameterInfo(self):
    params = []
    # Input geodatabases and feature datasets parameter
    params.append(arcpy.Parameter(
        displayName="Input Geodatabases and Feature Datasets",
        name="in_workspaces",
        datatype=["DEWorkspace", "DEFeatureDataset"],
        parameterType="Required",
        direction="Input",
        multiValue=True
    ))
    return params

Parameter function examples are from Defining parameter data types in a Python toolbox - Esri ArcGIS Desktop Help

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.