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