不具合
| 不具合 ID 番号 | BUG-000156786 |
|---|---|
| 送信されました | March 21, 2023 |
| 最終更新日 | April 29, 2025 |
| 適用対象 | ArcGIS Pro |
| 見つかったバージョン | 3.1 |
| オペレーティング システム | Windows OS |
| オペレーティング システムのバージョン | N/A |
| 修正されたバージョン | 3.3 |
| ステータス | As Designed |
In the user-provided code sample to reproduce the issue, the fieldsMappings.addTable(layer) object is creating the field mapping with all of the input fields, which is backwards; the target feature class table must first be added to the fieldMappings object before the input, so that the input fields automatically matches to the field names from the target when the names are the same. This matches the Append tool behavior in the Geoprocessing pane, where the field map loads all of the fields from the target, and users can map source fields from the input to those target fields. The code below works for the reproduced case provided for ArcGIS Pro 3.1:
## Start sample code
import sys, os, arcpy
input = os.path.join(arcpy.env.scriptWorkspace,'gpsdata.gdb\\points_source')
target = os.path.join(arcpy.env.scriptWorkspace,'gpsdata.gdb\\points_destination')
fieldMappings = arcpy.FieldMappings()
# Add all fields from target layer
fieldMappings.addTable(target)
# Add all fields from input layer, which will automatically match to field names from the target when the names are the same
fieldMappings.addTable(input)
arcpy.AddMessage(f"initial fieldmap = {fieldMappings.exportToString()}")
# Loop through all fields in the field map, and clean out the input fields from the target, so each field map only has an input from the input layer, which matches the behavior of the Append tool UI
for fmi in range(fieldMappings.fieldCount):
fm = fieldMappings.getFieldMap(fmi)
for targetfield_index in range(fm.inputFieldCount):
intable = fm.getInputTableName(targetfield_index)
if intable == arcpy.Describe(target).catalogPath:
fm.removeInputField(targetfield_index)
fieldMappings.replaceFieldMap(fmi, fm)
break
# find the existing guid field in the target layer
guid_field_index = fieldMappings.findFieldMapIndex("GUIDCopy")
guid_fieldmap = fieldMappings.getFieldMap(guid_field_index)
# add the input globalID field to the guid fieldmap
guid_fieldmap.addInputField(input, "GlobalID")
fieldMappings.replaceFieldMap(guid_field_index, guid_fieldmap)
arcpy.AddMessage(f"final fieldmap = {fieldMappings.exportToString()}")
arcpy.Append_management(input, target, "NO_TEST", fieldMappings)
## End sample code
不具合 ID: BUG-000156786
ソフトウェア:
ArcGIS エキスパートのサポートを受ける
Esri Support アプリのダウンロード