Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bixb0012/7758100497311f2268b01616a2310b3c to your computer and use it in GitHub Desktop.
Save bixb0012/7758100497311f2268b01616a2310b3c to your computer and use it in GitHub Desktop.
ArcPy: Add Dataset Property as Data Attribute
#!python
# Reference: 1) https://pro.arcgis.com/en/pro-app/arcpy/functions/describe.htm
# 2) https://pro.arcgis.com/en/pro-app/tool-reference/data-management/add-field.htm
# 3) https://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field.htm
import arcpy
# Example 1: Adding path attribute for tables and feature classes in workspace (ArcMap and Pro compatible)
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")
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment