Skip to content

Instantly share code, notes, and snippets.

@maptastik
Last active April 17, 2017 18:31
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 maptastik/f6346eb9ee534ceb1444d1a8e1c1f130 to your computer and use it in GitHub Desktop.
Save maptastik/f6346eb9ee534ceb1444d1a8e1c1f130 to your computer and use it in GitHub Desktop.
Add all the feature classes in an MXD to a geodatabase
'''
A Python script to take the feature classes in an MXD file and add them to a geodatabase
'''
import arcpy
# Specify MXD with data to send to GDB
# TODO Make this so you don't have to have ArcGIS open. User should be able to take a user input and export to GDB of choice
mxd = arcpy.mapping.MapDocument('CURRENT')
# Specify the data frame where your features are
# Allow users to input their own data frame name
df = arcpy.mapping.ListdataFrames(mxd, 'Layers')[0]
# Make list of data in data frame
df_list = list(df)
df_layer_list = []
d = 0
while d < len(df_list):
df_item = arcpy.mapping.ListLayers(mxd, '', df)[d].name
df_layer_list.append(df_item)
d+=1
arcpy.FeatureClassToGeodatabase_conversion(df_layer_list, '<path to output GDB>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment