Skip to main content
Tweeted twitter.com/StackGIS/status/1607209620736458752
naming
Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

Creating Field Mapping Parameterparameter in ArcpyArcPy Script

added 515 characters in body
Source Link

If the autopopulation is not possible, even getting the FieldMapping parameter to work properly would be an acceptable middle ground. Right now, the 'Add Input Field' never appears when right clicking a field map parameter. If I set the Field Mapping parameter to single value, clicking the window gives 2 options, Add Output Field and Reset. If I add an output field, right clicking that gives more options, Delete, Rename, Merge Rule, and Properties. None of which allow me to add an input field to the field map.

If the autopopulation is not possible, even getting the FieldMapping parameter to work properly would be an acceptable middle ground. Right now, the 'Add Input Field' never appears when right clicking a field map parameter. If I set the Field Mapping parameter to single value, clicking the window gives 2 options, Add Output Field and Reset. If I add an output field, right clicking that gives more options, Delete, Rename, Merge Rule, and Properties. None of which allow me to add an input field to the field map.

improved code formatting and remove thanks from the end of the question.
Source Link

Here is my code for the updateParameters method. param[0]/[1]param[0] and param[1] are feature layers and param[2]. param[2] is a field mappings parameter.

def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    if self.params[0].altered:
    self.params[2].value = arcpy.FieldMappings()
    for field in [a for a in arcpy.ListFields(self.params[0].value.dataSource) if not a.required]:
        fm = arcpy.FieldMap()
        fm.addInputField(self.params[0].value.dataSource,field.name)
        self.params[2].value.addFieldMap(fm)
    return

def updateParameters(self): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.""" if self.params[0].altered: self.params[2].value = arcpy.FieldMappings() for field in [a for a in arcpy.ListFields(self.params[0].value.dataSource) if not a.required]: fm = arcpy.FieldMap() fm.addInputField(self.params[0].value.dataSource,field.name) self.params[2].value.addFieldMap(fm) return I I have also tried this:

def updateParameters(self): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.""" if self.params[0].altered: fms = arcpy.FieldMappings() for field in [a for a in arcpy.ListFields(self.params[0].value.dataSource) if not a.required]: fm = arcpy.FieldMap() fm.addInputField(self.params[0].value.dataSource,field.name) fms.addFieldMap(fm) self.params[2].value = fms return

def updateParameters(self):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        if self.params[0].altered:
            fms = arcpy.FieldMappings()
            for field in [a for a in arcpy.ListFields(self.params[0].value.dataSource) if not a.required]:
                fm = arcpy.FieldMap()
                fm.addInputField(self.params[0].value.dataSource,field.name)
                fms.addFieldMap(fm)
            self.params[2].value = fms
        return

I can't find a single post on creating a field mapping parameter in a script similar to the append or spatial join tool. Here's hoping you have more experience here than I do.

Cheers

Here is my code for the updateParameters method. param[0]/[1] are feature layers and param[2] is a field mappings parameter.

def updateParameters(self): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.""" if self.params[0].altered: self.params[2].value = arcpy.FieldMappings() for field in [a for a in arcpy.ListFields(self.params[0].value.dataSource) if not a.required]: fm = arcpy.FieldMap() fm.addInputField(self.params[0].value.dataSource,field.name) self.params[2].value.addFieldMap(fm) return I have also tried this

def updateParameters(self): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.""" if self.params[0].altered: fms = arcpy.FieldMappings() for field in [a for a in arcpy.ListFields(self.params[0].value.dataSource) if not a.required]: fm = arcpy.FieldMap() fm.addInputField(self.params[0].value.dataSource,field.name) fms.addFieldMap(fm) self.params[2].value = fms return

I can't find a single post on creating a field mapping parameter in a script similar to the append or spatial join tool. Here's hoping you have more experience here than I do.

Cheers

Here is my code for the updateParameters method. param[0] and param[1] are feature layers. param[2] is a field mappings parameter.

def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    if self.params[0].altered:
    self.params[2].value = arcpy.FieldMappings()
    for field in [a for a in arcpy.ListFields(self.params[0].value.dataSource) if not a.required]:
        fm = arcpy.FieldMap()
        fm.addInputField(self.params[0].value.dataSource,field.name)
        self.params[2].value.addFieldMap(fm)
    return

I have also tried this:

def updateParameters(self):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        if self.params[0].altered:
            fms = arcpy.FieldMappings()
            for field in [a for a in arcpy.ListFields(self.params[0].value.dataSource) if not a.required]:
                fm = arcpy.FieldMap()
                fm.addInputField(self.params[0].value.dataSource,field.name)
                fms.addFieldMap(fm)
            self.params[2].value = fms
        return

I can't find a single post on creating a field mapping parameter in a script similar to the append or spatial join tool.

Source Link
Loading