Running external python script locks .aprx file to read only

346
1
11-17-2023 04:18 AM
AmosWall
New Contributor

Hi, I am making a script to run through a folder and find all the aprx files and update the transformations used for the maps within them. For the most part this is working however, the last aprx is modifies is often locked to readonly. It alternates each time it is run to either lock the aprx or not.

This is the script:

import os, arcpy

GISserver = r'C:\Users\user\Documents\Backup\C161946'

for root, dirs, files in os.walk(GISserver):
 for file in files:
  if file.endswith(".aprx"):
   try:
    aprx = arcpy.mp.ArcGISProject(os.path.join(root, file))
    print(os.path.join(root, file))
    for m in aprx.listMaps():
     print(m.name)
     print(m.transformations)
     TransformationDictionary = {'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
     m.updateTransformations(TransformationDictionary)
     print(m.transformations)
    print(aprx.isReadOnly)
    aprx.save()
    print(aprx.isReadOnly)
   except:
     print("Couldn't update transformations in " + os.path.join(root, file))

del aprx

 

The log it creates is:

runfile('C:/Users/user/Documents/Tool_Test_Project/Scripts/TransformationModifierTest.py', wdir='C:/Users/user/Documents/Tool_Test_Project/Scripts')
C:\Users\user\Documents\Backup\C161946_ArcGIS_Pro\C161946 - Copy.aprx
C161946-01-01-Overlay
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
C161946-01-01
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
C161946-AGOL
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
Layers1
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
Layers11
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
False
False


C:\Users\user\Documents\Backup\C161946_ArcGIS_Pro\C161946.aprx
C161946-01-01-Overlay
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
C161946-01-01
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
C161946-AGOL
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
Layers1
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
Layers11
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
False
False

 

 

runfile('C:/Users/user/Documents/Tool_Test_Project/Scripts/TransformationModifierTest.py', wdir='C:/Users/user/Documents/Tool_Test_Project/Scripts')
C:\Users\user\Documents\Backup\C161946_ArcGIS_Pro\C161946 - Copy.aprx
C161946-01-01-Overlay
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
C161946-01-01
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
C161946-AGOL
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
Layers1
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
Layers11
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
False
False


C:\Users\user\Documents\Backup\C161946_ArcGIS_Pro\C161946.aprx
C161946-01-01-Overlay
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
C161946-01-01
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
C161946-AGOL
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
Layers1
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
Layers11
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
{'2D': ['WGS_1984_To_OSGB_1936_OSTN15'], '3D': []}
True
Couldn't update transformations in C:\Users\user\Documents\Backup\C161946_ArcGIS_Pro\C161946.aprx

 

So as you can see this is from running the script twice the first time both projects are saved correctly but the second one was read only when manually opened. The second time through the second project failed to save because it was read only but was fine when opened afterwards. Does anybody know what is going on here and how to fix it?

1 Reply
TylerT
by
Occasional Contributor III

@AmosWall; I run into this all the time working in stand alone notebooks.  The 'del aprx' runs successfully, but upon opening ArcGIS Pro (or another script like you have done) the project is still locked.  The only work around I have found is to kill the kernel to release the lock.  Reference https://community.esri.com/t5/python-questions/python-causing-schema-lock-on-aprx/m-p/1132522 my post on the matter.

Tyler

 

0 Kudos