Updating and fixing data sources with arcpy mapping
If file names are not in FCList and RList, meaning #they do not already exist in the gdb, copy files to output gfb if fl_nm not in FCList and fl_nm not in RList: try: arcpy.Feature Class To Geodatabase_conversion(lyr,out_loc) except: print 'Input file ' lyr ' is not a feature class' try: arcpy.During a recent customer upgrade from ESRI 9.3 to 10SP3, we uncovered a last minute “gotcha” regarding over 1,000 map files floating around several share drives.Since the new production environment was now using a brand new Sql Server installation, with a different server name, all of the data sources that were attached to the map files would now be invalid.Also, you will need to make sure that there is a new data source file on the disk.Just setting a new source path does not work and will throw an exception. # Import system modules import arcpy, os #find all the MXD’s in the directory tree for root, sub Folders, files in os.walk(r”C:\Temp\Maps”): for filename in files: fullpath = join(root, filename) basename, extension = splitext(fullpath) if extension.lower() == “.mxd”: print “——————————” print filename #open the map document MXD = arcpy.mapping.In reality, this new “.sde” file would live on a shared directory, so all of the map files could reference it. Map Document(fullpath) #get all the layers for lyr in arcpy.mapping.
This typically is how I implement it, when needing to create a lot of layers with different definition queries quickly.Raster To Geodatabase_conversion(lyr,out_loc) except: print 'Input file ' lyr ' is not a feature class or a raster' #compare file names in fl_nm_list to lists of feature classes and rasters that #already exist in output gdb.If files exist in gdb that are not found in mxd #unique layers list, delete for gdb, fd, fc in Make Feature Layer requires two inputs, the input features and the output layer.The input features can be any type of feature class or layer. Output layer is the name of the layer to appear in the table of contents.