AnsweredAssumed Answered

export to jpeg loop

Question asked by renesch on Mar 30, 2012
Latest reply on Mar 3, 2015 by nathan_bush_fws
I created a loop to zoom to every shape in a shapefile and export that particular extent. The only problem is that the jpeg is given the number of the row as name. I want to give it the name of a field in de dbf. Does anybody have an idea how to do that?

import arcpy
from arcpy import env
from arcpy import mapping

mxd = arcpy.mapping.MapDocument(r"C:\gisbestanden\pythontest\test13.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]

fc = r"Z:\kaarten\COROP\coropmultipart.shp" 
count = str(arcpy.GetCount_management(fc))

x = 0

while x < int(count) + 1:
    rows = arcpy.SearchCursor(fc, "fid = " + str(x))
    for row in rows:
        xmin = row.shape.extent.XMin
        ymin = row.shape.extent.YMin
        xmax = row.shape.extent.XMax
        ymax = row.shape.extent.YMax
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        newExtent = df.extent
        newExtent.XMin, newExtent.YMin = xmin, ymin
        newExtent.XMax, newExtent.YMax = xmax, ymax
        df.extent = newExtent
        mapping.ExportToJPEG(mxd, r"C:\gisbestanden\pythontest\gemeentekaart\JPEG_" + str(x) + ".jpg")

        print "successfully printed JPG"
    x += 1