3

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
                                        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 ?

closed as off-topic by PolyGeo Jul 16 '17 at 1:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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