Skip to main content
5 of 10
added 140 characters in body
LZc
  • 29
  • 6

Python code migration

Can someone please help me with the migration of this code? It is used to export hundreds of maps and did its job perfectly. I got the code from this thread: https://gis.stackexchange.com/a/67520/157904

    >>> import_path = r"P:\project.mxd"   # Path of .mxd
export_path = r"P:\"   # Path of output file
field_name = "Taxon" # Name of field used to sort DDP

... mxd = arcpy.mapping.MapDocument(import_path) 
... for i in range(1, mxd.dataDrivenPages.pageCount + 1):
...    mxd.dataDrivenPages.currentPageID = i
...    row = mxd.dataDrivenPages.pageRow
...    print row.getValue(field_name)
...    arcpy.mapping.ExportToJPEG(mxd, export_path + "." + row.getValue(field_name) + ".jpg",resolution=600) 
... del mxd

Thank you, Phil


This is the error message i get (after @BERAs adaption):

AttributeError Traceback (most recent call last) In [3]: Line 5: ... mxd = arcpy.mapping.MapDocument(import_path)

AttributeError: module 'arcpy' has no attribute 'mapping'

Do I have to change arcpy.mapping.MapDocument(import_path) with arcpy.mp.ArcGISProject(aprx_path)?

LZc
  • 29
  • 6