Provide ability to create new ArcGIS Pro projects from Python

3518
18
09-01-2021 09:54 AM
Status: Under Consideration
Labels (1)
MaryGraceMcClellan
New Contributor III

I'm creating a script that will convert all of my MXDs to APRXs, and I find it extremely inconvenient that I can't create a new blank project from scratch form within ArcGIS Pro. This utility would make switching to ArcGIS Pro so much easier, along with the ability to create blank toolboxes. 

Edited to add: @Rhys-Donoghue posted a good workaround for this issue if anyone is interested. 

18 Comments
Rhys-Donoghue

@JeffBarrette and @MaryGraceMcClellan:

FYI, I have this working.  For one of my clients, I had to migrate hundreds of MXDs to ArcGIS Pro, and move their locations.  This is how I did it:

  1. Create a blank aprx and save it to a temporary location, e.g. C:\temp\blank.aprx
  2. For each MXD, import it into the aprx - e.g. aprx.importDocument(mxd)
  3. Save the aprx to the new location - e.g. aprx.saveACopy(new_aprx)
  4. Remap the datasources 
  5. Check the datasources were mapped correctly and run a few other validation tests

It only took half an hour or so to write the script, and then took a bit longer to test and make changes to handle exceptions.  I didn't have any issues with the new aprxs.

@MaryGraceMcClellan if you still need help with this, let me know and I will see if I still have a copy of my script, or I can rewrite the script for you when I get a chance.

MaryGraceMcClellan

@Rhys-Donoghue  -- thank you for the follow up! I actually ended up doing something similar within my script if memory serves. 

Rhys-Donoghue

@MaryGraceMcClellan - awesome.  I have hundreds of useful scripts like these.  I will start putting them online when I get a chance.

FredSpataro

@Rhys-Donoghue I came up with about the same process... however one thing i'm noticing is that the 'projects home folder' is still mapped to the original 'folder of the blank aprx'.  Did you figure out a way to remap this? 

JeffBarrette

@FredSpataro there is an ArcGISProject.homeFolder property.  In fact when trying to rebuild a project using the techniques above by importing into a blank project, there are many other items to consider.

ArcGISProject.databases / updateDatabases

ArcGISProject.defaultGeodatabase

ArcGISProject.defaultToolbox

ArcGISProject.folderConnections / updateFolderConnections

ArcGISProjec.homeFolder

ArcGISProject.styles / updateStyles (Pro 3.3)

ArcGISProject.toolboxes / updateToolboxes (Pro 3.3)

ArcGISProject.updateConnectionProperties

We are considering creating New Project but there are some technical hurdles we need to resolve.

Jeff - arcpy.mp team

JeffBarrette
Status changed to: Under Consideration

This is functionality we would like to provide in the arcpy.mp API but need to overcome a few technical hurdles.

FredSpataro

@JeffBarrette Thanks! Obviously this is not a normal type thing but now that i'm working thru it, I can see a lot of potential uses.  Couple other thoughts:

* It would be nice to have a similar method to ConvertLayoutFileToLayout for just the MAPX file.  Seems like this function already does the work since it imports the Layout and Map... why can't I do the same with just the map?  This technique is really useful for server-side geoprocessing services and the pagx/mapx files are easy to handle and keep in source control 

 

* I'm using 3.1.x right now (due to 11.1 at the Portal/Server level) and the .database and .updateDatabases isn't available until 3.2 ... took me a bit to figure out why i kept getting an error on thsoe.

* I was able to update the homeFolder, default toolbox, default geodatabase using the specific properties you mentioned. However it leaves references to the original atbx and gdb in the project.  Not a huge deal, someone can clean those open when they first open the project manually or otherwise not a big deal.  The database one probably cleans up when you use the updateDatabases() method but I'm not seeing anything that allow you to remove the toolbox.  removeItem() or a updateToolboxes method is probably needed as well? 

rhys-kdrm

@FredSpataro as @JeffBarrette mentioned above, this is how I would do it.