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:
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?
try the python syntax highlighting in the ... section of the toolbar
Thanks Dan_Patterson. I was looking for one but never saw that.
more info here /blogs/dan_patterson/2016/08/14/script-formatting
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