Select to view content in your preferred language

convert mxd to aprx problem

460
9
05-13-2025 02:32 PM
JinZ
by
Emerging Contributor

Hi

I am trying to covert mxd to aprx using python scripts. Here is my code. however when open the new aprx, it's empty. 

aprx = arcpy.mp.ArcGISProject(blank_aprx_path)

# Import the MXD document
aprx.importDocument(file_path)

# Save a copy of the new APRX in the same folder
aprx.saveACopy(os.path.join(dirpath, f'{mxd_name}.aprx'))

here is the content of mxd.

JinZ_0-1747152594369.png

please help.

Thanks very much

 

0 Kudos
9 Replies
DanPatterson
MVP Esteemed Contributor

code examples can be found here

ArcGISProject—ArcGIS Pro | Documentation

It appears that some of your data can't be located, hence the red ! marks


... sort of retired...
0 Kudos
JinZ
by
Emerging Contributor

JinZ_0-1747211372209.png

I tried to convert this mxd, still the result aprx is empty, the mxd use the sql geo databases, is it the reason? 

Thanks!

0 Kudos
DanPatterson
MVP Esteemed Contributor

There is no one-to-one conversion, there are limits

Migrate existing work—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
TonyAlmeida
MVP Regular Contributor

Here is something I've used in the past. Note, it will create an empty "Map", and you will have a map named whatever you had the Data frame named in the MXD. For example the Map frame in my mxd was named "Layers", so in the new .aprx I have a map named "Layers" and that is where the layers are.

import arcpy
from pathlib import Path

def convert_mxd_to_aprx(input_folder, template_path, output_folder=None):
    """
    Converts MXD files to APRX format using a specified template APRX.
    """

    input_folder = Path(input_folder).resolve()
    template_path = Path(template_path).resolve()

    # Validate paths
    if not input_folder.exists():
        print(f"Error: Input folder does not exist: {input_folder}")
        return
    if not template_path.exists() or template_path.suffix.lower() != ".aprx":
        print(f"Error: Invalid template APRX file: {template_path}")
        return

    output_folder = Path(output_folder).resolve() if output_folder else input_folder
    output_folder.mkdir(parents=True, exist_ok=True)

    print(f"\nSarting MXD to APRX conversion")
    print(f"put folder: {input_folder}")
    print(f"tput folder: {output_folder}")
    print(f"Tmplate APRX: {template_path}\n")

    for mxd_path in input_folder.rglob("*.mxd"):
        try:
            print(f"Cnverting: {mxd_path.name}")

            aprx = arcpy.mp.ArcGISProject(str(template_path))

            # Track original maps and layouts
            original_map_names = {m.name for m in aprx.listMaps()}
            original_layout_names = {l.name for l in aprx.listLayouts()}

            # Import MXD with layout
            aprx.importDocument(str(mxd_path), include_layout=True)

            # Detect new maps and layouts
            new_maps = [m for m in aprx.listMaps() if m.name not in original_map_names]
            new_layouts = [l for l in aprx.listLayouts() if l.name not in original_layout_names]

            if new_maps:
                imported_map = new_maps[0]
                layer_count = len(imported_map.listLayers())
                print(f"ported map: {imported_map.name} ({layer_count} layers)")
            else:
                print(f"No new map found.")

            if new_layouts:
                imported_layout = new_layouts[0]
                mapframes = imported_layout.listElements("MAPFRAME_ELEMENT")
                print(f"ported layout: {imported_layout.name} ({len(mapframes)} map frame(s))")
            else:
                print(f"No new layout found.")

            # Save the converted APRX
            output_aprx_path = output_folder / mxd_path.with_suffix(".aprx").name
            aprx.saveACopy(str(output_aprx_path))

            if output_aprx_path.exists():
                print(f"Saved: {output_aprx_path}\n")
            else:
                print(f"Failed to save: {output_aprx_path}\n")

        except Exception as e:
            print(f"Error processing {mxd_path.name}: {e}\n")
        finally:
            if 'aprx' in locals():
                del aprx

    print("All conversions complete.\n")

# Example usage
if __name__ == "__main__":
    convert_mxd_to_aprx(
        input_folder=r"C:\Temp\Test",
        template_path=r"C:\Temp\Test\MyNewProject.aprx",
        output_folder=r"C:\Temp\APRX_Output"
    )

 

0 Kudos
JinZ
by
Emerging Contributor

Thanks, just tried and not working for me. The converted aprx is still empty.

0 Kudos
DanPatterson
MVP Esteemed Contributor

Can you locate the missing data manually by adding it to a new project?  If not, then the data location may be the issue.


... sort of retired...
0 Kudos
TonyAlmeida
MVP Regular Contributor

After you run the script and when you first open the .aprx it will have an empty map. The script converts the arcmap map into a new map. You need check, under Catalog --> Project --> Maps, you should a another map--> this is your new map that was converted from Arcmap to Pro.

0 Kudos
JinZ
by
Emerging Contributor

yes, it's there. Thanks!

0 Kudos
JinZ
by
Emerging Contributor

If I use Acgis Pro , Insert-->ImportMap, select the same mxd, all data loaded. 

0 Kudos