thank you for your post. and also for the hint for syntax highlighting!
so here's the original code again.
cursor = arcpy.da.SearchCursor(lyrkartenausschn, [seitenzkartenausschn])
seitenliste = int(19)
del seitenliste
seitenliste = []
for row in cursor:
seitenliste.append(int(row[0]))
print seitenliste
for seite in seitenliste:
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.name == seitex:
elm.text = str(seite)
pfdausgabePDFeinzeln = pfadausgpdf[0:-4] +"_"+ str(seite) + ".pdf" #Path
arcpy.SelectLayerByAttribute_management (lyrkartenausschn, "NEW_SELECTION", seitenzkartenausschn + " = " + str(seite))
mxd.dataDrivenPages.exportToPDF(pfdausgabePDFeinzeln, "SELECTED") #PDF Export
mxd.dataDrivenPages.printPages(druckername, "SELECTED") # Print
mxdspeicher = ausgpdfmxd + "\\" + bewirtschafter + ".mxd"
mxd.saveACopy(mxdspeicher)
del row
del cursor
del seite
del seitenliste
del elm
arcpy.RefreshActiveView()
One thing I saw when reading your message: Line 52 isn't the line you guessed. I forgot to post it, sorry.
it's the following (Line 1):
arcpy.SelectLayerByAttribute_management(lyrkartenausschn, "NEW_SELECTION", seitenzkartenausschn + " IS NOT NULL")
arcpy.CalculateField_management(lyrkartenausschn, seitenzkartenausschn, "NULL", "VB")
This part of the code selects the "x in x of y" from the previous iteration and sets them to "NULL". So first it selects de extents which were used the previous times, then calculates the field to set the values to "NULL". As I see now, it's not really necessary to select it first, since I want to set all the values in that column to "NULL". But anyway, I can't see, why it shouldn't work.
Another thing I saw is that I must have forgotten to delete the first "seitenliste" (line 2+3) when I wrote the code.
I think there's no use for it. In the end, I think it must be integer, since in line 6 I make an integer out of the "row".
I convert the seitenliste to integer so I can make a for loop on it (line 8). and then in line 12 and 13 I need the same number to be written in the textfield and also to the path, so I think I really need to convert it twice?
So tomorrow I will try your suggestions and also delete the unnecessary rows.
An other question: is there a page where I can read about the .format ? I don't really understand how this works.
Thank you for your help! 🙂