I try to make this code work but I cannot find the error (not very familiar with python)It worked before I tried to add the loop though all shapefiles and I think the error lies somewhere at this line: featurelayer = arcpy.mapping.ListLayers(mxd, "*")[0]
Anyone can help?
import arcpy from arcpy import envimport os#Specify the workspace, map document and the data frameenv.workspace = "C:\\Users\\\\Maps.Code"mxd = arcpy.mapping.MapDocument("C:\\Users\\\Maps.Code\\test1.mxd")#output file folderoutPath = "D:\\MxdMapAutomation\\Test2\\" # loop through all shapefiles in env.workspacefor featureclass in arcpy.ListFeatureClasses("*"): #loop through fields in featureclass field_names = [f.name for f in arcpy.ListFields(featureclass)] field_names = field_names[19:len(attrlist)-2])) #skip some fields # layer which has to change the attribute field featurelayer = arcpy.mapping.ListLayers(mxd, "*")[0] # text element that has to change (e.g. title...) title = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "map_title")[0] for attr in field_names: #if featurelayer.symbologyType == "GRADUATED_COLORS": # change value field featurelayer.symbology.valueField = attr #featurelayer.symbology.addAllValues() featurelayer.symbology.reclassify() # change tilte title.text = attr # update view arcpy.RefreshActiveView() arcpy.RefreshTOC() # export as jpeg outJPEG = os.path.join(outPath, attr + ".jpg") arcpy.mapping.ExportToJPEG(mxd, outJPEG, "PAGE_LAYOUT", 200, 200, 300, False, "24-BIT_TRUE_COLOR", 90, False)del mxd
أكثر...
Anyone can help?
import arcpy from arcpy import envimport os#Specify the workspace, map document and the data frameenv.workspace = "C:\\Users\\\\Maps.Code"mxd = arcpy.mapping.MapDocument("C:\\Users\\\Maps.Code\\test1.mxd")#output file folderoutPath = "D:\\MxdMapAutomation\\Test2\\" # loop through all shapefiles in env.workspacefor featureclass in arcpy.ListFeatureClasses("*"): #loop through fields in featureclass field_names = [f.name for f in arcpy.ListFields(featureclass)] field_names = field_names[19:len(attrlist)-2])) #skip some fields # layer which has to change the attribute field featurelayer = arcpy.mapping.ListLayers(mxd, "*")[0] # text element that has to change (e.g. title...) title = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "map_title")[0] for attr in field_names: #if featurelayer.symbologyType == "GRADUATED_COLORS": # change value field featurelayer.symbology.valueField = attr #featurelayer.symbology.addAllValues() featurelayer.symbology.reclassify() # change tilte title.text = attr # update view arcpy.RefreshActiveView() arcpy.RefreshTOC() # export as jpeg outJPEG = os.path.join(outPath, attr + ".jpg") arcpy.mapping.ExportToJPEG(mxd, outJPEG, "PAGE_LAYOUT", 200, 200, 300, False, "24-BIT_TRUE_COLOR", 90, False)del mxd
أكثر...