Loop doesn't work when trying to export

Discussion created by alma29 on Sep 13, 2012
Latest reply on Sep 19, 2012 by smartgirl
I'm trying to create a script to export only those parcels with scale = 1040, but the script will only export the 2 first parcels and I have 3 parcels wich scale is 1040 on the .mxd, seems like the loop doesn't work correctly. Also in order to ensure that the script will do something I have to open the .mxd, go to the first parcel and save the file, if I save the .mxd being on the third or fourth page the script won't do anything, and to make it worse when I took a look at the PDF of the second parcel that was exported, I discovered that on the line that says the scale, the PDF had a wrong scale, it had the text "Scale: 1030" and I don't have any parcel with that scale!

Here are the scales of the parcels on the .mxd that I'm trying to export:

Parcel 1 = Escale: 1040

Parcel 2 = Escale: 1040

Parcel 3 = Escale: 1140

Parcel 4 = Escale: 980

Parcel 5 = Escale: 1000

Parcel 6 = Escale: 1350

Parcel 7 = Escale: 1040

My doubts are:

1.- What is wrong on the loop that the script only exports the first 2 parcels and not
the 3 parcels with scale = 1040

2.- Why the second PDF exported has the wrong Scale (1030) on the Scale line

I will be grateful if someone can help me to figure out what I'm doing wrong

Here is the script:

import arcpy, string

mxd = arcpy.mapping.MapDocument(r"D:\00salida\Plantilla_8x11.mxd")

pageNum = 1

ddp = mxd.dataDrivenPages

df = arcpy.mapping.ListDataFrames(mxd)[0]

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):

    if df.scale == 1040:

       print "\nCurrent Value of df.scale " + (str(df.scale))

       mxd.dataDrivenPages.currentPageID = pageNum

       print "EXPORTING " + (str(ddp.pageRow.CVEGEO))

       print "Again Current Value of df.scale: "

       print df.scale

       arcpy.mapping.ExportToPDF(mxd, r"\00salida\PDFS\M" + str(ddp.pageRow.CVEGEO) + ".PDF")

del pageNum, mxd

Here is what I get on the screen as output:


Current Value of df.scale 1040.0

EXPORTING 1102700010125024

Again Current Value of df.scale:


Current Value of df.scale 1040.0

EXPORTING 1102700010125015

Again Current Value of df.scale: