import arcpy mxd = "C:/ArcPyTests/Untitled.mxd" mapdoc = arcpy.mapping.MapDocument(mxd) counties = "C:/ArcPyTests/countyPopulation.shp" rows = arcpy.SearchCursor(counties) output = "C:/ArcPyTests/" df = arcpy.mapping.ListDataFrames(mapdoc) for row in rows: mapdoc.extent = row.Shape.extent df.zoomToSelectedFeatures(mapdoc.extent) outputname = row.County arcpy.mapping.ExportToPDF (mapdoc, outputname + ".PDF") print "Output " + outputname + " complete" del mapdoc
Solved! Go to Solution.
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum # Get the row from the attribute table of the index layer row = mxd.dataDrivenPages.pageRow # Get the value from the field called tilename, e.g. ab1234. (This should be a string field) name = row.getValue("TILE_NAME") # Set Output location outputlocation = arcpy.GetParameterAsText(0) # Concatenate into whole path name outputName = outputlocation + "\\" + name + "_ArcMap" + ".tif" #Set the data frame so the output can be cropped to the data frame extent df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] #Set the resolution dpi= arcpy.GetParameterAsText(1) #Specify the compression type Compression = arcpy.GetParameterAsText(2) # Export to tiff arcpy.mapping.ExportToTIFF(mxd, outputName, df, df_export_width=5153, df_export_height=5107, tiff_compression=Compression, color_mode="24-BIT_TRUE_COLOR", resolution=dpi) # Clean up del mxd
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum # Get the row from the attribute table of the index layer row = mxd.dataDrivenPages.pageRow # Get the value from the field called tilename, e.g. ab1234. (This should be a string field) name = row.getValue("TILE_NAME") # Set Output location outputlocation = arcpy.GetParameterAsText(0) # Concatenate into whole path name outputName = outputlocation + "\\" + name + "_ArcMap" + ".tif" #Set the data frame so the output can be cropped to the data frame extent df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] #Set the resolution dpi= arcpy.GetParameterAsText(1) #Specify the compression type Compression = arcpy.GetParameterAsText(2) # Export to tiff arcpy.mapping.ExportToTIFF(mxd, outputName, df, df_export_width=5153, df_export_height=5107, tiff_compression=Compression, color_mode="24-BIT_TRUE_COLOR", resolution=dpi) # Clean up del mxd
Traceback (most recent call last): File "C:/ArcPyTests/createPDF_datadrivenpages.py", line 5, in <module> for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): AttributeError: 'str' object has no attribute 'dataDrivenPages'
import arcpy mxd = "C:/ArcPyTests/Untitled.mxd" mapdoc = arcpy.mapping.MapDocument(mxd) print "import complete" for pageNum in range(1, mapdoc.dataDrivenPages.pageCount + 1): mapdoc.dataDrivenPages.currentPageID = pageNum
import arcpy mxd = arcpy.mapping.MapDocument(r"C:/ArcPyTests/Untitled.mxd") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum