maptastik
4/17/2017 - 5:54 PM

Add all the feature classes in an MXD to a geodatabase

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>')