import arcpy, os, json, traceback, sys, datetime from arcpy import mapping from arcpy import env mxd_out = r'D:\Temp\Blank.mxd' now = datetime.datetime.now() log = r'D:\Temp\Invertory_' + now.strftime("%Y-%m-%d" + '_' + "%H_%M_%S") + '_Error.log' if arcpy.Exists(log): arcpy.Delete_management(log) if arcpy.Exists(mxd_out): arcpy.Delete_management(mxd_out) mapService = {} jsonDump = json.dumps(mapService) result = mapping.ConvertWebMapToMapDocument(jsonDump) mxd = result.mapDocument my_mxd = mxd.saveACopy(mxd_out) env.workspace = r"D:\Temp\Layers" contents = [] print 'Starting' for dirpath, dirnames, datatypes in arcpy.da.Walk(env.workspace): contents.append(os.path.join(dirpath)) for item in contents: if arcpy.Exists(item): arcpy.env.workspace = item listType = [arcpy.ListFeatureClasses, arcpy.ListDatasets] for list in listType: datasetList = list("*", 'All') # Iterate over the feature classes for dataset in datasetList: data = item + '\\' + dataset desc = arcpy.Describe(data) print data + ' : ' + desc.dataType # Crack open the map mxd_new = arcpy.mapping.MapDocument(mxd_out) df = arcpy.mapping.ListDataFrames(mxd_new, '*')[0] try: lyrFile = arcpy.mapping.Layer(data) if desc.dataType == 'RasterDataset': layerType = arcpy.management.MakeRasterLayer result = layerType(lyrFile, 'temp_layer') layer_object = result.getOutput(0) arcpy.mapping.AddLayer(df, layer_object) else: result = arcpy.management.MakeFeatureLayer(lyrFile, 'temp_layer') layer_object = result.getOutput(0) arcpy.mapping.AddLayer(df, layer_object) # Set correct extent df.zoomToSelectedFeatures() nm = os.path.splitext(dataset)[0] # Compute an output file name out_file_name = (r"D:\Temp\Output" + "\\" + nm + '.jpg') # Export Image of data frame arcpy.mapping.ExportToJPEG(mxd_new, out_file_name, df, 300, 300, ) # Pull the layer out of the data frame to make room for the next one arcpy.mapping.RemoveLayer(df, layer_object) # Delete the GP layer arcpy.management.Delete('temp_layer') except: arcpy.ExecuteError arcpy.AddError(arcpy.GetMessage(2)) f=open(log, 'at') f.write(data + '\n') f.close() del mxd, mxd_new if arcpy.Exists(mxd_out): arcpy.Delete_management(mxd_out) del mxd_out
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.