Hi All,
I have been using python script for conversion of MXDs to APRX files. we are able to create the aprx files but when I open its empty no layers or properties in newly converted aprx file. below is the script
import os
import pathlib
import arcpy
ogDir = r'D:\MXDs'
dirContents = os.listdir(ogDir)
for folder_path, subfolders, filenames in os.walk(ogDir):
for file in filenames:
if file[-4:] == '.mxd':
aprx = arcpy.mp.ArcGISProject('Current')
filePath = pathlib.Path(folder_path) / file
mxd = file[:-4]
aprx.importDocument(filePath)
aprx.saveACopy(folder_path + '\\' + mxd + '.aprx')
Kindly help me out where I can get same as like my MXD into aprx file.
Thanks,
Naveen
Hello,
In the documentation examples it's noted that the use of the "current" keyword can only works within the arcgis pro python windows.
ArcGISProject—ArcGIS Pro | Documentation
To make it work, you need to create manually a blank/empty project and open it explicitly :
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\blank.aprx")
Hi @CedricDespierreCorporon I have created blank aprx file and passed the this as parameter. we are getting the below error.
Traceback (most recent call last):
File "<string>", line 13, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 409, in __init__
self._arc_object = arcgisscripting._mapping.ArcGISProject(*gp_fixargs((aprx_path,), True))
OSError: D:\mxd_test\blank.aprx
Hello,
usually, OS errors could be related to 3 things :
My code looks the same as yours and works.
The only difference is where your code reads
aprx = arcpy.mp.ArcGISProject('Current')
mine reads
aprx = arcpy.mp.ArcGISProject(r'C:\Users\NAME\Documents\ArcGIS\Projects\MyProjectTest\MyProjectTest.aprx')
I opened a project , saved it, and added the script to run from the toolbox.
If you go to Project Tab > Info there is an easy copy path button for pasting your project name
Also, before hand I went to the Project Tab > Package manager and cloned my environment and updated all my packages
I am running on Pro 3.1.3
Python-2.0
Hi, I have changed the code as suggested by you created new blank project and passed aprx as parameter to ArcGISProject by removing current. Script ran successfully but the same issue as mentioned above getting same empty aprx file.
Hello @naveenbesri : the code should create a new map within the project with the MXD layers, and it will not add them to the default opened map. Checks the list of maps it should be there.
Hi, I did the same. Mxds got converted to aprx in the mentioned folder and after that when I open I saw no layers added which I have posted above. Kindly help
I ran the python script in python window. below is the screenshot
and after that aprx files have been created but no data in it.
Hello, the file size of each aprx is different so they should not be empty.
Imported MXD should be present in a "new" map within the project : you can have multiple maps in one project with arcgis pro.