how to add the name of FeatureClasses to the names of the joined fields with Arcpy?

1095
4
12-18-2021 10:59 PM
khalidechlouchi
New Contributor II

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

 

khalidechlouchi_0-1639897009181.png

 

Tags (1)
0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor
0 Kudos
khalidechlouchi
New Contributor II

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)
0 Kudos
DanPatterson
MVP Esteemed Contributor

Re: How can I include featureClass names with join... - Esri Community

provides an alternate solution using numpy/arcpy functionality


... sort of retired...
0 Kudos
khalidechlouchi
New Contributor II

Thank you Dan, I will try. 

0 Kudos