I have a folder and would like to iterate through each MXD and take each SDE feature class that is in it and place in a new folder and file geodatabase, with a new MXD using the file geodatabase paths.
- folder with original MXD name
- new MXD in new folder with original MXD name
- new file geodatabase with all feature classes from MXD
Each new MXD should have the above associated with it.
I have a solid understanding of each function that I would like to write aside from iterating and copying MXDs and their features, how should this be done with arcpy?
This script iterates through a folder and all MXDs and prints the MXD and feature classes used in the MXD. I would like to further this by accessing each feature class from
arcpy.mapping and sending those to a file geodatabase. And making a new MXD with the new feature classes.
import arcpy, os, datetime folderPath = 'C:\MXD_test' #Loop through each MXD file for root, dirs, files in os.walk(folderPath): for file in files: # files is a list of files in the current directory if file.lower().endswith(".mxd"): fullpath = os.path.join(root, file) # root is the current directory #Reference MXD mxd = arcpy.mapping.MapDocument(fullpath) DFList = arcpy.mapping.ListDataFrames(mxd) for df in DFList: # Format output values if df.description == "": descValue = "None" else: descValue = df.description # ==== Note the new descName variable descName = df.name lyrList = arcpy.mapping.ListLayers(mxd, "", df) for lyr in lyrList: lyrName = lyr.name if lyr.supports("dataSource"): lyrDatasource = lyr.dataSource else: lyrDatasource = "N/A" print lyrDatasource print fullpath