Using ArcPy, how do I add the name of FeatureClasses to the names of the joined fields?
This is my code which I think helps explain what I am looking for.
thank you for your help
-------------------------------------------------------------------- import arcpy arcpy.env.workspace = arcpy.GetParameterAsText(0) fc = arcpy.GetParameterAsText(1) featureList = arcpy.ListFeatureClasses() field_names = [f.name for f in arcpy.ListFields(fc)] for feature in featureList: fields = ["AAAA"] arcpy.JoinField_management("BATI", "ID_BATI", feature, "ID_BATI", fields) ------------------------------------------------------------------
check out Add Join (Data Management)—ArcGIS Pro | Documentation
Thank you for your feedback!, I've checked the documentation. I chose JoinField because I can specify the fields to join but AddJoin it join all the fields and that for a dozen featureClass it will give me a hundred fields in the table to delete after and leave only the desired fields.
I modified my code by inserting (arcpy.env.qualifiedFieldNames = True) and arcpy.MakeFeatureLayer_management in my code. but the output field name still does not include the featureClasses names.
import arcpy
# Set environment settings
arcpy.env.workspace = arcpy.GetParameterAsText(0)
arcpy.env.qualifiedFieldNames = True
# Set local variables
FcCible = "BATI"
featurelayer = "Batijoin"
IDjoin = "ID_BATI"
# Create a feature layer from the BATI featureclass
arcpy.MakeFeatureLayer_management(FcCible, featurelayer)
featureList = arcpy.ListFeatureClasses()
for feature in featureList:
fields = ["AAAA"]
arcpy.JoinField_management(featurelayer, IDjoin, feature, IDjoin, fields)
# Copy the layer to a new permanent feature class
outFeature = "atest.gdb/Batijoin"
arcpy.CopyFeatures_management(featurelayer, outFeature)
Re: How can I include featureClass names with join... - Esri Community
provides an alternate solution using numpy/arcpy functionality
Thank you Dan, I will try.