I'd like to write a Python script to help me deal with making illustrations that are filtered by some number in each layer, and then I want DataDrivenPages to zoom into the corresponding view. However, I have encountered an error as follows:
![微信图片_20240424165535.png 微信图片_20240424165535.png](https://community.esri.com/t5/image/serverpage/image-id/101963i86971AE88FDCE757/image-size/large?v=v2&px=999)
I have checked the document about 'pageRow', and I knew it was read-only, but it could then be read and/or modified as necessary. But I don't know why this code cannot work.
This is the code:
import arcpy
import arcpy.mapping as mapping
import xlrd
work_book = xlrd.open_workbook(r'C:\Users\39470\Desktop\schedule.xls')
size = work_book.sheets()[0].nrows
kqbh, kqmc = [], []
for i in range(1, size):
kqmc.append(work_book.sheets()[0].row(i)[2].value)
kqbh.append(work_book.sheets()[0].row(i)[3].value)
mxd = mapping.MapDocument('CURRENT')
layers = mapping.ListLayers(mxd)
for number, name in zip(kqbh, kqmc):
if number != '':
mxd.dataDrivenPages.pageRow.setValue('KQBH', number)
for lyr in layers:
if lyr.isFeatureLayer:
if lyr.symbologyType == 'UNIQUE_VALUES':
sym = lyr.symbology
df = mapping.ListDataFrames(mxd)[0]
sym.valueField = 'KQBH'
sym.classValues = [number]
sym.classLabels = [lyr.name]
sym.showOtherValues = False
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
mxd.saveACopy(r'C:\Users\39470\Desktop\illustrations\\' + name + '.mxd')
Can anyone help me?
Thanks!