justin.preikschas_exp

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

Discussion created by justin.preikschas_exp on Dec 13, 2016
Latest reply on Dec 13, 2016 by Dan_Patterson

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? 

Outcomes