How to add file types to a multiple data type arcpy parameter in a Python toolbox?

537
4
12-21-2021 10:54 PM
calin_gi
New Contributor II

In my custom Python toolbox, I would like to create a similar input parameter as the "Input KML File" in the "KML To Layer" tool, i.e. allowing a layer to be selected by dropdown and by opening it from a file dialog (see screenshot below).

I can almost make this work by using the following code:

 

 

 

param0 = arcpy.Parameter(
            displayName="Input KML/KMZ File",
            name="input_kml",
            datatype=["GPKMLLayer","DEFile"],
            parameterType="Required",
            direction="Input",
        )

 

 

 

The problem is that I now get the choose any file type instead of just kml and kmz files.

If I add the following code, I get an error:

 

 

param0.filter.list = ["kml", "kmz"]

 

 

How can I make this work?

calin_gi_0-1640156149023.png

 

0 Kudos
4 Replies
2Quiker
Occasional Contributor II

maybe multivalue= True, 

aram0 = arcpy.Parameter(
            displayName="Input KML/KMZ File",
            name="input_kml",
            datatype=["GPKMLLayer","DEFile"],
            parameterType="Required",
            multivalue= True,
            direction="Input",
        )

 

0 Kudos
Luke_Pinner
MVP Regular Contributor

If you just use datatype="GPKMLLayer", the tool will accept a KML layer in the map from the dropdown, or a .kml/kmz file from the file dialog.  You'll be able to select a non .kml/kmz file in the file dialog, but the tool will show a validation error:

 

param0 = arcpy.Parameter(
            displayName="Input KML/KMZ File",
            name="input_kml",
            datatype="GPKMLLayer",
            parameterType="Required",
            direction="Input",
        )

 

 

unnamed.png

 

0 Kudos
calin_gi
New Contributor II

I am just wondering how Esri did it for the KML to layer tool though...

0 Kudos
Luke_Pinner
MVP Regular Contributor

I'm not sure it's possible with a Python Toolbox, perhaps a bug report or an ArcGIS Pro Ideas feature request about supporting filters for composite datatypes (e.g. parameter.filters[n].list = ["kml", "kmz"]) like is possible for value table parameters.  In a PYT, a parameter with a composite datatype does have a .filters property, but all the elements (one for each datatype) are None, not a filter object).

It is possible using a script tool instead of a python toolbox though...

Luke_Pinner_0-1641243985958.png

 

 

0 Kudos