Skip to content

Instantly share code, notes, and snippets.

@brambow
Created May 22, 2018 13:58
Show Gist options
  • Save brambow/120c8df8bad4a11cb6fc1859ea223cc7 to your computer and use it in GitHub Desktop.
Save brambow/120c8df8bad4a11cb6fc1859ea223cc7 to your computer and use it in GitHub Desktop.
Create a Data Dictionary for ArcGIS Pro Feature Classes
# generate a data dictionary from an ArcGIS feature class
# tested with ArcGIS Pro/Python3
# Run from command prompt in ArcGIS Pro environment
# Takes 2 arguments: 1) path to feature class 2) path for output CSV file
# Example: python C:\arcpy_data_dictionary.py C:\yourgeodatabase.gdb\featureclassname C:\output.csv
import arcpy
import sys
import csv
table = sys.argv[1]
outfile = sys.argv[2]
fields = arcpy.ListFields(table)
headings = ["name", "alias", "type", "length"]
data = [headings]
for field in fields:
row = [field.name, field.aliasName, field.type, field.length]
data.append(row)
file = open(outfile, 'w', newline='')
with file:
writer = csv.writer(file)
writer.writerows(data)
print('CSV file written')
@amaracini
Copy link

Thanks for this, I'm trying to run and have attempted numerous combinations but can't seem to get it to run. Where do I put the path or arguments? This is one way that made sense to me but it doesn't work:

generate a data dictionary from an ArcGIS feature class

tested with ArcGIS Pro/Python3

Run from command prompt in ArcGIS Pro environment

Takes 2 arguments: 1) path to feature class 2) path for output CSV file

Example: python C:\arcpy_data_dictionary.py C:\yourgeodatabase.gdb\featureclassname C:\output.csv

import arcpy
import sys
import csv

table = sys.argv[D:\Data_Sets\working.gdb\WinnCoParcel]
outfile = sys.argv[D:\Data_Sets\WinnCoParcel.csv]

fields = arcpy.ListFields(table)
headings = ["name", "alias", "type", "length"]
data = [headings]

for field in fields:
row = [field.name, field.aliasName, field.type, field.length]
data.append(row)

file = open(outfile, 'w', newline='')
with file:
writer = csv.writer(file)
writer.writerows(data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment