2

I have followed the advice on the post How to automatically generate useful scales for data driven pages in ArcGIS desktop. I followed the advice, but when the process executes it was only the last value that is stored in all the fields in my column "scale". However, I want each value saved in the ID of the appropriate polygon.

Here is the Code:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\workspace\MyMXD.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for i in range(0, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = i
   if df.scale < 50:
     df.scale = 50
   elif df.scale < 100:
     df.scale = 100
   elif df.scale < 200:
     df.scale = 200
   elif df.scale < 500:
     df.scale = 500
   elif df.scale < 1000:
     df.scale = 1000
   elif df.scale < 2000:
     df.scale = 2000
   elif df.scale < 5000:
     df.scale = 5000
   elif df.scale < 10000:
     df.scale = 10000

  InTable = "C:\workspace\MyShapeFile.shp" 
  with arcpy.da.UpdateCursor(InTable,["scale"]) as UpCur:
  for row in UpCur:
     row[0] = df.scale
   UpCur.updateRow(row)
0
2

You have to remember (store in list) df.scale at each iteration. See if this will work

import arcpy
mxd = arcpy.mapping.MapDocument(r'd:\scratch\_wbench.mxd')
df = arcpy.mapping.ListDataFrames(mxd)[0]
listOfScales=[]
goodScales=[50,100,200,500,1000,2000,5000,10000,500000]
for i in range(1, mxd.dataDrivenPages.pageCount + 1):
   mxd.dataDrivenPages.currentPageID = i
   curScale=df.scale
   for sc in goodScales:
      if sc>curScale: break
   listOfScales.append(sc)

InTable = r'd:\scratch\tlas.shp' 
with arcpy.da.UpdateCursor(InTable,["scale"]) as UpCur:
   for row in UpCur:
      row[0] = listOfScales.pop(0)
      UpCur.updateRow(row)

Note my answer assumes that page order equal order of shapes in output file. Also note that pageid starts with 1, not zero

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.