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?
maybe multivalue= True,
aram0 = arcpy.Parameter(
displayName="Input KML/KMZ File",
name="input_kml",
datatype=["GPKMLLayer","DEFile"],
parameterType="Required",
multivalue= True,
direction="Input",
)
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",
)
I am just wondering how Esri did it for the KML to layer tool though...
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...