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.
<SPAN class="comment token"># First parameter</SPAN>
param0 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Parameter<SPAN class="punctuation token">(</SPAN>
displayName<SPAN class="operator token">=</SPAN><SPAN class="string token">"Input Features"</SPAN><SPAN class="punctuation token">,</SPAN>
name<SPAN class="operator token">=</SPAN><SPAN class="string token">"in_features"</SPAN><SPAN class="punctuation token">,</SPAN>
datatype<SPAN class="operator token">=</SPAN><SPAN class="string token">"GPFeatureLayer"</SPAN><SPAN class="punctuation token">,</SPAN>
parameterType<SPAN class="operator token">=</SPAN><SPAN class="string token">"Required"</SPAN><SPAN class="punctuation token">,</SPAN>
direction<SPAN class="operator token">=</SPAN><SPAN class="string token">"Input"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Third parameter</SPAN>
param2 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Parameter<SPAN class="punctuation token">(</SPAN>
displayName<SPAN class="operator token">=</SPAN><SPAN class="string token">"Output Features"</SPAN><SPAN class="punctuation token">,</SPAN>
name<SPAN class="operator token">=</SPAN><SPAN class="string token">"out_features"</SPAN><SPAN class="punctuation token">,</SPAN>
datatype<SPAN class="operator token">=</SPAN><SPAN class="string token">"GPFeatureLayer"</SPAN><SPAN class="punctuation token">,</SPAN>
parameterType<SPAN class="operator token">=</SPAN><SPAN class="string token">"Derived"</SPAN><SPAN class="punctuation token">,</SPAN>
direction<SPAN class="operator token">=</SPAN><SPAN class="string token">"Output"</SPAN><SPAN class="punctuation token">)</SPAN>
param2<SPAN class="punctuation token">.</SPAN>parameterDependencies <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>param0<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">]</SPAN>
param2<SPAN class="punctuation token">.</SPAN>schema<SPAN class="punctuation token">.</SPAN>clone <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
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 <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"<string>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">481</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> getParameterInfo
AttributeError<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'NoneType'</SPAN> object has no attribute <SPAN class="string token">'clone'</SPAN>
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?
<SPAN class="comment token"># Input Table</SPAN>
input_table <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Parameter<SPAN class="punctuation token">(</SPAN>
displayName<SPAN class="operator token">=</SPAN><SPAN class="string token">"Table or Feature Class"</SPAN><SPAN class="punctuation token">,</SPAN>
name<SPAN class="operator token">=</SPAN><SPAN class="string token">"input_table"</SPAN><SPAN class="punctuation token">,</SPAN>
datatype<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"GPFeatureLayer"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"GPTableView"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
parameterType<SPAN class="operator token">=</SPAN><SPAN class="string token">"Required"</SPAN><SPAN class="punctuation token">,</SPAN>
direction<SPAN class="operator token">=</SPAN><SPAN class="string token">"Input"</SPAN><SPAN class="punctuation token">)</SPAN>
params<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>input_table<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Derived Output Table</SPAN>
output_table <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Parameter<SPAN class="punctuation token">(</SPAN>
displayName<SPAN class="operator token">=</SPAN><SPAN class="string token">"Derived Output Table or Feature Class"</SPAN><SPAN class="punctuation token">,</SPAN>
name<SPAN class="operator token">=</SPAN><SPAN class="string token">"output_table"</SPAN><SPAN class="punctuation token">,</SPAN>
datatype<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"GPFeatureLayer"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"GPTableView"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
parameterType<SPAN class="operator token">=</SPAN><SPAN class="string token">"Derived"</SPAN><SPAN class="punctuation token">,</SPAN>
direction<SPAN class="operator token">=</SPAN><SPAN class="string token">"Output"</SPAN><SPAN class="punctuation token">)</SPAN>
output_table<SPAN class="punctuation token">.</SPAN>parameterDependencies <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>input_table<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">]</SPAN>
output_table<SPAN class="punctuation token">.</SPAN>schema<SPAN class="punctuation token">.</SPAN>clone <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
params<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>output_table<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I am currently running version 10.4
Someone over at GIS SE did some testing and led me to the following conclusions:
- When I changed all the data types to ["GPFeatureLayer", "GPTableView"] it gave me the error.
- I then changed all the data types to ["GPFeatureLayer"], and it still gave me the error.
- 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?