Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Updating Field Mappings Parameter on table selection in Python Toolbox?

$
0
0

I am building a python toolbox with ArcPy and would like to associate an input feature class parameter with a field mapping, so that once user selects the input feature class the field map populates with the input fields.

I have tried;

  • fieldMapParameter.addTable(feature_class_parameter.name) in the updateParameters method but throws error ParameterObject: Get attribute: addTable does not exist
  • Setting fieldMapParameter.parameterDependencies = [param1.name] doesn’t seem to have an effect.

    def getParameterInfo(self):
        """Define parameter definitions"""
        feature_class_parameter = arcpy.Parameter(displayName="Input_Table", #0
                                        name="fc_settlements",
                                        datatype="DEFeatureClass",
                                        parameterType="Required",
                                        direction="Input")
    
        fieldMapParameter = arcpy.Parameter(displayName="Primary Settlement Fields", #1
                                name="primary_fieldmap",
                                datatype="GPFieldMapping",
                                parameterType="Optional",
                                enabled=True,
                                direction="Input" )
        fieldMapParameter.parameterDependencies = [feature_class_parameter.name] # Doesn't seem to work
        params = [feature_class_parameter,fieldMapParameter]
        return params
    
    def updateParameters(self, parameters):
        if parameters[0].altered:
           parameters[1].addTable(parameters[0].valueAsText) # Fails with method not found
        return
    

Full Toolbox

How do I associate these two parameters so they work like field mapping for the native tools such as Merge/Append etc ?


Viewing all articles
Browse latest Browse all 767

Trending Articles