AnsweredAssumed Answered

Python data driven turn off layer and modify scale bar

Question asked by alex92190 on Oct 31, 2012
Latest reply on Nov 7, 2012 by alex92190
Hi all,
I am looking for a script that would turn off a specific layer for certain data driven pages (for instance: turn-off layer page 25 and 29).

I wrote a quick script that does not work (I would like to get help with)

import arcpy, os
#Specify map doc, data frame and table
mxd = arcpy.mapping.MapDocument(r"K:\Projects_1\Caltrans\00543_09_Willits_from_URS\mapdoc\Crossection_2012\Crossection_20121024.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
mapLyr = arcpy.mapping.ListLayers(mxd, "Mapbook_table", df)[0]
#Map book
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
    rows = arcpy.SearchCursor(mapLyr)
    for row in rows:
  source = row.getValue ("Source")
  if source == "Willits":
   lyrName = "On-Site Mitigation Area_Python"
   lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
   lyr.visible = True
                        arcpy.mapping.ExportToPDF(mxd, r"K:\\Working\\Alex_Gole\\" + Try + ".pdf")
   lyr.visible = False

del lyr
del mxd, df


Since each data driven has its own dependent scale, I would also like to incorporate in this script some code that would modify the scale bar  (for instance: if scale is below 1:150, scale bar is 0 to 50, or if scale is 1:1000, scale bar is 1 to 100). Could anybody help with this,
Thanks,
Alex

Outcomes