Last active
July 31, 2019 18:18
-
-
Save bixb0012/7758100497311f2268b01616a2310b3c to your computer and use it in GitHub Desktop.
ArcPy: Add Dataset Property as Data Attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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