Select to view content in your preferred language

Import and Rename .mapx Files Python Question

329
0
03-27-2024 12:50 PM
Smileyk_mdt
New Contributor

Hi,

Looking to see if I can fix the following code block. I want to import .mapx docs into a Pro project and rename them with the name of the mapx filename. I was successful at importing them in an earlier version without the names, but wanted to rename them because they get named as "Layers1"

 

Here's the code:

 

 

import arcpy
import os

workspace = r"S:\GeoInfo\All_Staff\Kyle_S\python_notebooks\Test"

aprx = arcpy.mp.ArcGISProject(r"S:\GeoInfo\All_Staff\Kyle_S\python_notebooks\Test\ImportMapDocs.aprx")

for root, dirs, files in os.walk(workspace):
    for file in files:
        if file.endswith(".mapx"):
            mapx_path = os.path.join(root, file)
            print("MAPX Path :" + mapx_path)
            mapx_basename = os.path.splitext(os.path.basename(mapx_path))[0]
            print("MAPX NAME :" +  mapx_basename)
            new_map = aprx.importDocument(mapx_path)
            new_map.name = mapx_basename
            print(f"Imported and renamed {file}  into the Import Docs project")
aprx.save()
del aprx

 

 

 

I get an Error saying 'Nonetype' object has no attribute name. Seems I have to define a new map object somehow?

Tags (3)
0 Kudos
0 Replies