<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Map Automation - Seeking Scripting Solution for Opening an APRX from Python IDLE in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1614849#M95783</link>
    <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/450062"&gt;@CMorneau&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You're definitely correct that Python is maintaining a lock on the file so it cannot be opened. I've had similar issues doing something pretty close to this. Would it be possible to share a snippet of your code?&lt;/P&gt;&lt;P&gt;From what I've done, I think it's possible to use Python's del functionality to delete an object. It would be used something like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject(target_aprx)

# Do your things around here

del aprx

time.sleep(1) # 1 second sleep to make sure that the object is deleted

# I would have the os.system attempt to open the file here&lt;/LI-CODE&gt;&lt;P&gt;This is one of the ways that I've gotten it to work, del will not remove the file but remove the object itself, here is documentation for that, hopefully it works!&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.w3schools.com/python/ref_keyword_del.asp" target="_blank"&gt;https://www.w3schools.com/python/ref_keyword_del.asp&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
    <pubDate>Thu, 15 May 2025 01:03:50 GMT</pubDate>
    <dc:creator>CodyPatterson</dc:creator>
    <dc:date>2025-05-15T01:03:50Z</dc:date>
    <item>
      <title>Map Automation - Seeking Scripting Solution for Opening an APRX from Python IDLE</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1614825#M95782</link>
      <description>&lt;P&gt;ArcGIS Pro 3.4.3&lt;/P&gt;&lt;P&gt;Hello! I am developing a Python script that is intended to be run outside of an ArcGIS Pro session (e.g., from Python IDLE). The script copies an APRX to a different folder &amp;amp; renames it. It contains seven template layouts, each of which are renamed by the script per customer requirements. Likewise, the script updates a few text elements &amp;amp; resizes/repositions additional elements (rectangle graphics, legends, etc.). So far, so good - works great.&lt;/P&gt;&lt;P&gt;Ideally, though, I'd also like the script to automatically open the APRX in Pro once it has completed &amp;amp; saved all of the updates. I cannot figure out the coding to do so. After the last elements are updated, I execute &lt;EM&gt;save()&lt;/EM&gt;. But if I also run &lt;EM&gt;os.system("start " + aprx)&lt;/EM&gt;, where &lt;EM&gt;aprx&lt;/EM&gt; has been defined with a correctly formatted filepath, an error message is returned basically stating no-can-do, that the file is already in use by another application. From what I can tell, Python IDLE is that very application.&lt;/P&gt;&lt;P&gt;Of course, I could click-open my copied APRX directly from File Explorer or call it upon opening Pro. But for efficiency's sake, I want to bundle that operation with the map automation script. Note: in my script, I start with importing the &lt;EM&gt;arcpy&lt;/EM&gt;, &lt;EM&gt;shutil&lt;/EM&gt;, &amp;amp; &lt;EM&gt;os&lt;/EM&gt; modules. Note also: I'm not an experienced Python programmer, so forgive me if the answer is painfully obvious. Hopefully, a solution for this posting will help not only me, but others at my level of experience. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 14 May 2025 23:59:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1614825#M95782</guid>
      <dc:creator>CMorneau</dc:creator>
      <dc:date>2025-05-14T23:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: Map Automation - Seeking Scripting Solution for Opening an APRX from Python IDLE</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1614849#M95783</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/450062"&gt;@CMorneau&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You're definitely correct that Python is maintaining a lock on the file so it cannot be opened. I've had similar issues doing something pretty close to this. Would it be possible to share a snippet of your code?&lt;/P&gt;&lt;P&gt;From what I've done, I think it's possible to use Python's del functionality to delete an object. It would be used something like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject(target_aprx)

# Do your things around here

del aprx

time.sleep(1) # 1 second sleep to make sure that the object is deleted

# I would have the os.system attempt to open the file here&lt;/LI-CODE&gt;&lt;P&gt;This is one of the ways that I've gotten it to work, del will not remove the file but remove the object itself, here is documentation for that, hopefully it works!&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.w3schools.com/python/ref_keyword_del.asp" target="_blank"&gt;https://www.w3schools.com/python/ref_keyword_del.asp&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 01:03:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1614849#M95783</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2025-05-15T01:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Map Automation - Seeking Scripting Solution for Opening an APRX from Python IDLE</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1615051#M95796</link>
      <description>&lt;P&gt;Thank you, Cody.&amp;nbsp; Yesterday, I had given some thought to trying &lt;EM&gt;del aprx&lt;/EM&gt;, but I ran out of time.&amp;nbsp; I'll give that a try today, along with &lt;EM&gt;time.sleep(1)&lt;/EM&gt;.&amp;nbsp; That's interesting - I have not seen that before, so I appreciate learning something new.&amp;nbsp; Also, thank you for sharing the link to the w3schools site.&lt;/P&gt;&lt;P&gt;Per your request, below is a shortened &amp;amp; annotated version of my script:&lt;/P&gt;&lt;P&gt;import shutil, arcpy, os&lt;/P&gt;&lt;P&gt;# Enter parameters: Ticket, Case, Project, Project Folder, etc.:&lt;BR /&gt;Ticket = '123456'&lt;BR /&gt;Case = 'RPPL2025123456' # Case #&lt;BR /&gt;CaseType = 'CUP' # Case type&lt;BR /&gt;ProjectNum = 'PRJ-123456'&lt;/P&gt;&lt;P&gt;DestFolder = r'C:\GIS\PROJECTS\GIS_Public_Hearing_Maps\Projects' # From internal customer request&lt;/P&gt;&lt;P&gt;# APRX with seven template layouts:&lt;BR /&gt;Source = r'C:\GIS\PROJECTS\DRP_CURRENT_PLANNING\GIS_Public_Hearing_Maps\Hearing_Maps_Templates_Standard.aprx'&lt;/P&gt;&lt;P&gt;# Create the variable APRX:&lt;BR /&gt;APRX = DestFolder + '\\' + Case + '_T' + Ticket + '.aprx'&lt;BR /&gt;print(APRX) # To verify correct formatting.&lt;/P&gt;&lt;P&gt;# Copy &amp;amp; rename the APRX (see below for results):&lt;BR /&gt;shutil.copyfile(Source, APRX)&lt;/P&gt;&lt;P&gt;# Rename the layouts:&lt;BR /&gt;p = arcpy.mp.ArcGISProject(APRX)&lt;BR /&gt;CaseTicket = Case + '_' + Ticket&lt;BR /&gt;for lyt in p.listLayouts():&lt;BR /&gt;oldName = lyt.name&lt;BR /&gt;nameRep = oldName.replace('Template_8x11', CaseTicket)&lt;BR /&gt;lyt.name = nameRep&lt;/P&gt;&lt;P&gt;# Not included in this snippet are all the subsequent steps to update &amp;amp;/or reposition elements in each of the seven layouts. Coding for these steps works fine.&lt;/P&gt;&lt;P&gt;p.save()&lt;/P&gt;&lt;P&gt;os.system("start " + APRX) # This doesn't work while the Python IDLE is still open with the above script. It throws an error message saying that the file is already in use (Python IDLE appears to have the lock on it).&lt;/P&gt;&lt;P&gt;# But this works fine for opening the APRX in read+write mode when the Python IDLE session is closed &amp;amp; re-opened:&lt;BR /&gt;import arcpy, shutil, os&lt;BR /&gt;aprx = r'C:\GIS\PROJECTS\GIS_Public_Hearing_Maps\Projects\RPPL2025123456_T123456.aprx'&lt;BR /&gt;os.system("start " + aprx)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 15:58:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1615051#M95796</guid>
      <dc:creator>CMorneau</dc:creator>
      <dc:date>2025-05-15T15:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Map Automation - Seeking Scripting Solution for Opening an APRX from Python IDLE</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1615054#M95797</link>
      <description>&lt;P&gt;Attached is a better view of it from Notepad++:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 16:08:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1615054#M95797</guid>
      <dc:creator>CMorneau</dc:creator>
      <dc:date>2025-05-15T16:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Map Automation - Seeking Scripting Solution for Opening an APRX from Python IDLE</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1615143#M95803</link>
      <description>&lt;P&gt;Thus far, I have not been successful with this proposed solution.&amp;nbsp; Quite possibly, it cannot be done.&amp;nbsp; I stumbled upon an 03-20-2024 reply from Esri's Robert LeClair on a posting entitled&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-arcgisproject-aprx-lock-issue/m-p/1398589" target="_self"&gt;arcpy.mp.ArcGISProject .aprx lock issue&lt;/A&gt;.&amp;nbsp; In it, he wrote the following:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;So there was an enhancement request, ENH-000140298 - Add a method to the arcpy.mp.ArcGISProject() object that will close the project and release locks held by a script. But it was marked as "will not be addressed." The explanation was "Locks on a project file can be eliminated by either closing the Python shell (vs the script editor) or by calling del on the appropriate variables. The method has little value when run in a script outside of the application and also inside the application."&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 18:44:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1615143#M95803</guid>
      <dc:creator>CMorneau</dc:creator>
      <dc:date>2025-05-15T18:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Map Automation - Seeking Scripting Solution for Opening an APRX from Python IDLE</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1615269#M95820</link>
      <description>&lt;P&gt;Not where I can test, but I have overcome file locking issues like this before using *.bat files.&lt;/P&gt;&lt;P&gt;I create a python script that similar to:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os

modify = r"D:\path\to\batchfile\modify_aprx.bat"
open_aprx = r"D:\path\to\batchfile\open_aprx.bat"
aprx = r"D:\path\to\projectfile\filename.aprx"

os.system(modify )
os.system("start " + aprx)&lt;/LI-CODE&gt;&lt;P&gt;The modify_aprx.bat file will have something similar to:&lt;/P&gt;&lt;LI-CODE lang="c"&gt; Run my Python script
call "%PROGRAMFILES%\ArcGIS\Pro\bin\Python\Scripts\propy" "D:\path\to\script\modify_aprx.py"
@echo Finished&lt;/LI-CODE&gt;&lt;P&gt;Where modify_aprx.py is your python script that does the work.&lt;/P&gt;&lt;P&gt;So, the python that is doing the work is running in the first system shell, and once it is done, it closes and deletes/removes all locks/links to the data.&lt;/P&gt;&lt;P&gt;Then, it should be 'free' to open after the first cmd closes.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 May 2025 00:09:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/map-automation-seeking-scripting-solution-for/m-p/1615269#M95820</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2025-05-16T00:09:10Z</dc:date>
    </item>
  </channel>
</rss>

