ArcGISProject.saveACopy modifies "CURRENT"

05-12-2022 12:30 AM
New Contributor III


I've encountered weird behaviour in the saveACopy method of the class. It seems that it modifies the value of "CURRENT". I've assembled a short code sample:

import arcpy

def PrintFilePathOfCurrentArcGISProject(msg):
    # Open the "CURRENT" project and print the file path
    aprx ="CURRENT")
    arcpy.AddMessage(f"{msg}: {aprx.filePath}")

def main():
    PrintFilePathOfCurrentArcGISProject("Before opening \"CURRENT\" aprx")

    aprx ="CURRENT")

    PrintFilePathOfCurrentArcGISProject("After saveACopy")

if __name__ == "__main__":


When running the script in ArcGIS Pro 2.9.3, the output is:

Before opening "CURRENT" aprx: C:\Users\Madlener\Documents\ArcGIS\Projects\MyProject\MyProject.aprx
After saveACopy: D:\test_copy.aprx

I wonder if this is a bug (I certainly think it is one..) If it's not a bug, this behaviour should be documented in the saveACopy method. The problem is that I cannot restore the old value of "CURRENT" by any means. If there's a way though, I'd be glad if somebody could let me know.

Thanks in advance


0 Kudos
2 Replies
MVP Esteemed Contributor

why not reopen the original one again

... sort of retired...
0 Kudos
New Contributor III

Of course I can store the inital value of aprx.filePath in a variable and reopen the project again later but my scenario is a bit different:

My Script Tool basically creates a copy of the currently opened ArcGIS Pro project to a user defined location and updates some layer connection settings. Now that saveACopy modifies the value of "CURRENT", the script obviously can't be run more than one time because the second time it's run, "CURRENT" points to the copy and not to the currently opened Project anymore.

Now maybe (I haven't checked) there's the possibility of having a global variable that is persistent across multiple tool executions so I can set it the very first time.


0 Kudos