I am building a python toolbox with ArcPy and would like to associate an input feature class parameter with a field mapping. I want the input dialog to work as it does in many built-in geoprocessing tools (e.g. Dissolve), 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
        fieldMapParameter = arcpy.Parameter(displayName="Primary Settlement Fields", #1
                                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

Full Toolbox

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

  • 1
    Changing the updateParameters to : def updateParameters(self, parameters): if parameters[0].altered: tfms = arcpy.FieldMappings() tfms.addTable(parameters[0].valueAsText) parameters[1].value = tfms.exportToString() Seems to work, but it's pretty slow. There must be a more 'natural' way to set this ? I basically have a set of output fields that I'd like to be available to map from the input feature class. – kes Jun 29 '15 at 21:19
  • I am working on the same exact functionality. Did you ever get this working? Thanks in advance. – user57119 Aug 23 '15 at 16:12
  • If you wish to write your comment up as an answer, just flag this question to be re-opened so that you can do so. – PolyGeo Jul 16 '17 at 1:09