3

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 and when do I need 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

  • Could you also add the code for input_table definition? – Paul Dec 12 '16 at 20:54
1

Take a look at this ESRI documentation on the clone property.

My guess is that your output needs to be set to DEFeatureClass or DETable instead of GPFeatureLayer and GPTableView. Or maybe one of the two data types you're using is invalid, or it can only take 1 data type.

I'm going to copy/paste some information from the first link I mentioned because it does a good job explaining what the clone property does.


Clone

If true, you are instructing geoprocessing to make an exact copy (clone) of the description in the first dependent parameter. The default value is false. Typically, you set clone to true in the getParameterInfo method. If the first dependent parameter is a multivalue (a list of values), the first value in the multivalue list is cloned.

  • If parameter.parameterType is "Derived", an exact copy is made. This is the behavior of the Add Field tool.
  • If parameter.parameterType is "Required", an exact copy is also made, but the catalog path to the dataset is changed.

After setting clone to true, all rule-based methods, such as featureTypeRule, geometryTypeRule, and extentRule, are set to "FirstDependency".


ESRI's example:

class ExampleClipTool2(object):
    def __init__(self):
        self.label       = "Example Clip tool 2"
        self.description = "Using clone to set rules to FirstDependency, then overriding the extent rule"

    def getParameterInfo(self):
        # Input feature class
        param0 = arcpy.Parameter(
            displayName="Input Features",
            name="in_features",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input")

        # Input table
        param1 = arcpy.Parameter(
            displayName="Clip Features",
            name="clip_features",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input")

        # Input workspace
        param2 = arcpy.Parameter(
            displayName="Output Feature Class",
            name="out_feature_class",
            datatype="DEFeatureClass",
            parameterType="Required",
            direction="Output")

        # Set the dependencies for the output and its schema properties
        #  The two input parameters are feature classes.
        #
        param2.parameterDependencies = [param0.name, param1.name]
        param2.schema.clone = True

        params = [param0, param1, param2]

        return params

    def updateParameters(self, parameters):
        # The only property of the clone that changes is that the extent 
        #  of the output is the intersection of the input features 
        #  and the clip features (parameter 1)
        #
        parameters[0].schema.extentRule = "Intersection"
        return

EDIT

I just created a Python toolbox and copy/pasted ESRI's example.

It opened fine, but when I changed all the data types to ["GPFeatureLayer", "GPTableView"] it gave me the same error you're getting. 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.

LAST EDIT (moving comment into main answer)

This is the key part: After setting clone to true, all rule-based methods, such as featureTypeRule, geometryTypeRule, and extentRule, are set to "FirstDependency".

So, it sounds like it just sets those rules the same as the first parameter in parameterDependencies. As for why you use it, I'm not entirely sure, maybe just "good practice" when you know the input/output are very similar. But I'd say it's just for the Validation side, if you want to get VERY specific on what the Output schema should be. And clone just sets the Output the same as the Input for those 3 rules.

  • That was good information, thanks. But sadly setting the type to DEFeatureClass or DETable didn't help. That is yet another mystery to me, since the example from Esri I posted did not use the "DE" types in the derived output. One day maybe I can figure out when to use those instead... Any other ideas on the clone error? – jmpreiks Dec 13 '16 at 18:32
  • Have you tried only using 1 data type for the input and output instead of 2? – ianbroad Dec 13 '16 at 18:34
  • 1
    Yeah I'll post it over there. Thanks again for your help. If I get an answer I'll post it here. – jmpreiks Dec 13 '16 at 18:41
  • 1
    So, I just did some testing with the ESRI example in my post. When I set all the data types to ["GPFeatureLayer", "GPTableView"] I get the same error message as you. If I change all the data types to ["GPFeatureLayer"], then I still get the error message. But when I changed all the data types to "GPFeatureLayer", then it worked fine. When you changed yours to a single data type, did you leave the brackets? Try removing them. I edited my post with this information. – ianbroad Dec 13 '16 at 19:11
  • 1
    @jmpreiks to me, this is the key part: After setting clone to true, all rule-based methods, such as featureTypeRule, geometryTypeRule, and extentRule, are set to "FirstDependency". So, it sounds like it just sets those rules the same as the first parameter in parameterDependencies. As for why you use it, I'm not entirely sure, maybe just "good practice" when you know the input/output are very similar. But I'd say it's just for the Validation side, if you want to get VERY specific on what the Output schema should be. And clone just sets the Output the same as the Input for those 3 rules. – ianbroad Dec 14 '16 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.