0

What do I need to change to migrate this ArcMap code to ArcGIS Pro?

It is used to export hundreds of maps and did its job perfectly.

I got the code from this Q&A: 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

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)?

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Mar 20, 2023 at 8:38
4
  • 1
    Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site works Commented Mar 20, 2023 at 8:42
  • 1
    where are you migrating to? what seems not to work? Commented Mar 20, 2023 at 8:42
  • 1
    What is the problem you are having with that code? Commented Mar 20, 2023 at 8:56
  • print row.getValue(field_name) should be print(row.getValue(field_name)) since ArcMap is python 2 and ArcGIS Pro p3 Commented Mar 20, 2023 at 9:45

1 Answer 1

4

To migrate your code from ArcMap to ArcGIS Pro, you need to change all references from arcpy.mapping to arcpy.mp. This is covered in the documentation here. Have a look at the code sample #2 for MapSeries for a similar piece of code to your example.

bixb0012
2,8681 gold badge7 silver badges19 bronze badges
answered Mar 20, 2023 at 11:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.