Using “schema.clone = True” on Python Toolbox Parameter?

1087
4
12-13-2016 12:25 PM
Justin_P
New Contributor III

Cross-posted from GIS Stack Exchange. I have created a few different ArcGIS Python Toolboxes, but one thing I can't quite understand is when to apply "schema.clone = True" to a parameter. All of the examples I have seen show that I should be using it for derived parameters, as shown below, taken from Parameter Dependencies.

# First parameter
param0 = arcpy.Parameter(
   displayName="Input Features",
   name="in_features",
   datatype="GPFeatureLayer",
   parameterType="Required",
   direction="Input")

# Third parameter
param2 = arcpy.Parameter(
   displayName="Output Features",
   name="out_features",
   datatype="GPFeatureLayer",
   parameterType="Derived",
   direction="Output")
param2.parameterDependencies = [param0.name]
param2.schema.clone = True‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

However, when I try that on my code, it says the Tool is invalid when looking at it in Catalog. It gives me the following error when I click on the "Why..." button.

Traceback (most recent call last):
   File "<string>", line 481, in getParameterInfo
AttributeError: 'NoneType' object has no attribute 'clone'‍‍‍

Here is what my code looks like. It works perfectly when I remove the schema clone line, which is confusing me. What exactly does that line do for me and when do I need it if it works fine without it?

# Input Table
input_table = arcpy.Parameter(
   displayName="Table or Feature Class",
   name="input_table",
   datatype=["GPFeatureLayer", "GPTableView"],
   parameterType="Required",
   direction="Input")
params.append(input_table)

# Derived Output Table
output_table = arcpy.Parameter(
   displayName="Derived Output Table or Feature Class",
   name="output_table",
   datatype=["GPFeatureLayer", "GPTableView"],
   parameterType="Derived",
   direction="Output")
output_table.parameterDependencies = [input_table.name]
output_table.schema.clone = True
params.append(output_table)

I am currently running version 10.4

Someone over at GIS SE did some testing and led me to the following conclusions:

  1. When I changed all the data types to ["GPFeatureLayer", "GPTableView"] it gave me the error.
  2. I then changed all the data types to ["GPFeatureLayer"], and it still gave me the error.
  3. Finally, I changed all the data types to "GPFeatureLayer", and it opened fine again.

This tells me you can only have 1 data type, and it cannot be in brackets.

So, how do you handle cases where you need multiple possible input types? That seems like a pretty common use case. Or do you simply not need to include the schema clone line at all? 

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

try the python syntax highlighting  in the ... section of the toolbar

0 Kudos
Justin_P
New Contributor III

Thanks Dan_Patterson. I was looking for one but never saw that.

0 Kudos
DanPatterson_Retired
MVP Emeritus
0 Kudos
DanPatterson_Retired
MVP Emeritus

According to this, it makes a clone of the first dependent parameter, which must be throwing a None (NoneType) and expects only one value as input, perhaps tossing everything if there is more than one

Schema—Help | ArcGIS Desktop You will have to check the details

ADDENDUM

type
(Read Only)
The schema type: Feature, Table, Raster, or Container (for workspaces and feature datasets).
String

perhaps the type is expecting one, and container for the latter

0 Kudos