#import modules and define workspace import arcpy import os import traceback workspace = arcpy.env.workspace = r"C:/temp" print workspace arcpy.env.overwriteOutput = True #Define map document mxDoc = arcpy.mapping.MapDocument(r"C:/temp/PSL_Parcel.mxd") print mxDoc #List the first dataframe (named Layers) in the map document df = arcpy.mapping.ListDataFrames(mxDoc, "Layers") [0] #List first map layer (which is the parcels layer) in dataframe parcelLayer = arcpy.mapping.ListLayers(mxDoc,"",df) [0] print parcelLayer parcelField = "APN_NU_1" #Create a feature layer to make selections on selectingLayer = arcpy.MakeFeatureLayer_management(parcelLayer, "parcelLayer_lyr") #Set up cursor: rows = arcpy.SearchCursor(selectingLayer) recordsCounted = 0 #Find the field, select each record and get values for row in rows: APN = row.getValue(parcelField) whereClause = "APN_NU_1 = '%s'" % APN arcpy.management.SelectLayerByAttribute(selectingLayer, "NEW_SELECTION", whereClause) print row.getValue(parcelField) recordsCounted += 1 #Export map with selected record to PDF pdfLocation = 'C:\\temp\\' pdfName = pdfLocation + APN + '.pdf' arcpy.mapping.ExportToPDF(mxDoc, pdfName) print recordsCounted del row, rows #Clean up feature layers from memory and to debug and or rerun script arcpy.Delete_management(selectingLayer)
Solved! Go to Solution.
for row in rows: print row.getValue('APN_NU_1') APN = row.getValue('APN_NU_1') print "||" + APN + "||" whereClause = "APN_NU_1 = '" + APN + "'" print "|" + whereClause + "|" arcpy.SelectLayerByAttribute_management(parcelLayer, "NEW_SELECTION", whereClause)
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Temp\temp.mxd") df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0] Layer = arcpy.mapping.ListLayers(mxd, "*Counties*")[0] county = 'Red River' sql1 = "\"NAME\" = " + "\'" + county + "\'" rows = arcpy.SearchCursor(Layer, sql1) for row in rows: print row.getValue('OBJECTID') oid = str(row.getValue('OBJECTID')) sql2 = "\"OBJECTID\" = " + oid arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", sql2) df.extent = Layer.getSelectedExtent(False) df.scale = df.scale * 1.1 arcpy.mapping.ExportToPDF(mxd, r"C:\Temp\RedRiver" + oid + ".pdf")
Try this...
For each county (in your case, parcel) that matches the where clause in the Search Cursor, I select it, then set the extent of the data frame to be that of the selected feature (plus 10%), then I export it it to pdf.import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Temp\temp.mxd") df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0] Layer = arcpy.mapping.ListLayers(mxd, "*Counties*")[0] county = 'Red River' sql1 = "\"NAME\" = " + "\'" + county + "\'" rows = arcpy.SearchCursor(Layer, sql1) for row in rows: print row.getValue('OBJECTID') oid = str(row.getValue('OBJECTID')) sql2 = "\"OBJECTID\" = " + oid arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", sql2) df.extent = Layer.getSelectedExtent(False) df.scale = df.scale * 1.1 arcpy.mapping.ExportToPDF(mxd, r"C:\Temp\RedRiver" + oid + ".pdf")
#import modules and define workspace import arcpy import os import traceback workspace = arcpy.env.workspace = r"E:/Projects/PSL" print workspace arcpy.env.overwriteOutput = True #Define map document mxDoc = arcpy.mapping.MapDocument(r"E:/Projects/PSL/PSL_Parcel.mxd") print mxDoc #List the first dataframe (named Layers) in the map document df = arcpy.mapping.ListDataFrames(mxDoc, "Layers") [0] print df #List first map layer (which is the parcels layer) in dataframe parcelLayer = arcpy.mapping.ListLayers(mxDoc,"",df) [0] #Set up a Search Cursor to go thru the attribute table and get row values to update the layout text #First set up variable, then read the row values and verify recordsCounted = 0 rows = arcpy.SearchCursor(parcelLayer) for row in rows: print row.getValue('APN_NU_1') APN = row.getValue('APN_NU_1') whereClause = """ 'APN_NU_1' = APN """ arcpy.SelectLayerByAttribute_management(parcelLayer, "NEW_SELECTION", whereClause) df.extent = parcelLayer.getSelectedExtent (False) df.scale = df.scale * 1.1 recordsCounted += 1 pdfLocation = 'E:\\Projects\\PSL\\temp\\' pdfName = pdfLocation + APN + '.pdf' arcpy.mapping.ExportToPDF(mxDoc, pdfName)
for row in rows: print row.getValue('APN_NU_1') APN = row.getValue('APN_NU_1') print "||" + APN + "||" whereClause = "APN_NU_1 = '" + APN + "'" print "|" + whereClause + "|" arcpy.SelectLayerByAttribute_management(parcelLayer, "NEW_SELECTION", whereClause)