Select to view content in your preferred language

set map in contents pane

454
3
01-22-2025 01:32 AM
JosepFaneca
New Contributor
Hello everyone,
I am importing mxd projects to aprx with a python script. 
I need the imported map to appear in the content panel.
Right now it only appears in the Catalog panel. My script is the following:

current_dir =  os.path.abspath(os.path.dirname(__file__))
arcpy.env.workspace = current_dir
mxds = arcpy.ListFiles("*.mxd")
for i in mxds:
newAprx=i[:-4]+".aprx"
print("Convirtiendo " + i + " en " + newAprx)

tempProject= "temp.aprx" #blank template
x=os.path.join(current_dir, newAprx)

#--- Creating APRX ---
aprx=arcpy.mp.ArcGISProject(tempProject)
aprx.saveACopy(x)
aprx.importDocument(current_dir+"//"+i)
aprx.saveACopy(x)

 

3 Replies
LauraBecht
Frequent Contributor

So, it looks like there was a similar post some time ago and they recently found a solution.  That post referenced importing a mapx and opening the map (Solved: Re: Open map after importing .mapx using arcpy - Esri Community).

So, I would adapt that code something like this:

aprx.importDocument(current_dir+"//"+i)
aprx.openView()
aprx.saveACopy(x)
JosepFaneca
New Contributor

Hi,

Sorry, but ArcGISProject class does not have the method openView(), is a method of Map class.

I'm runnig a python file from an IDE and this part of script  has no effect:

project = arcpy.mp.ArcGISProject(newAprx)
project.closeViews("MAPS")
project.listMaps()[0].openView()
project.save()

however, in the ArcGis Pro python window console it adds the map to the contents pane:

before

JosepFaneca_0-1737632041448.png

after run command in python window

JosepFaneca_1-1737632169726.png

 

 

 

Clubdebambos
MVP Regular Contributor

Hi @JosepFaneca 

I get the same functionality, you should report as a possible bug and/or create a new idea for this functionality to work outside of ArcGIS Pro in a standalone script.

~ learn.finaldraftmapping.com