Feature class name calculation

2767
1
02-01-2019 10:07 AM
IandeNeeve2
New Contributor II

I merged a LOT of feature classes from different geodatabases into one MERGED feature class. I need to bring the name of the individual feature classes that comprise the MERGED feature class into a NAME field in the MERGED feature class. 

A simple way that i thought would be to iterate through the individual feature classes and calculate their NAME fields with their feature class name. Python or model builder ought to be able to do this, but i don't have the time right now to work out how. DOES ANYONE KNOW A WAY TO DO THIS QUICKLY???

0 Kudos
1 Reply
JoshuaBixby
MVP Esteemed Contributor

Various forms of this question have been asked over time:

From a response of mine in one of those above (ArcPy (ArcMap): Add Dataset Property as Data Attribute · GitHub):

# Reference: 1) http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-functions/describe-object-properties.htm
#            2) http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/add-field.htm
#            3) http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/calculate-field.htm

import arcpy

# Example 1: Adding path attribute for tables and feature classes in workspace
workspace = # Workspace containing feature classes

desc = arcpy.Describe(workspace) 
for child in desc.children:  
    if child.datasetType not in ('Table', 'FeatureClass'): continue  
    arcpy.AddField_management(child.catalogPath, "FC_NAME", "TEXT")  
    arcpy.CalculateField_management(child.catalogPath,  
                                    "FC_NAME",  
                                    "'{}'".format(child.baseName),  
                                    "PYTHON_9.3")