Updating text elements not working when using APRX path vs "CURRENT"

by M.Standish   Last Updated August 14, 2019 14:22 PM

Hello beginner here and trying to expand into using python with ArcPro. I have a working script that will update a specified text element in all layouts in ArcPro, in my case it's a project name.

project_name = 'Test Project'
aprx = arcpy.mp.ArcGISProject("CURRENT")
for lyt in aprx.listLayouts():
    for elm in lyt.listElements("TEXT_ELEMENT", "Project Name"):
        elm.text = project_name
aprx.save()

My problem comes when I try to run the script outside of a running ArcPro instance and use the APRX path rather than "Current" in arcpy.mp.ArcGISProject()

import arcpy

project_number = "12345"
project_name = "Test Project"
project_number_group = project_number[:2]
newpath = "N:\\Projects\\" + project_number_group + "000\\" + project_number + "_" + project_name.replace(" ","_")
aprx = arcpy.mp.ArcGISProject(newpath + "\\APRX\\Project_Figures.aprx")
for lyt in aprx.listLayouts():
    for elm in lyt.listElements("TEXT_ELEMENT", "Project Name"):
        elm.text = project_name
aprx.save()

The odd thing is when I go line by line things appear to be normal, the aprx variable calls the correct project, the path appears correctly, it's just nothing actually updates when I run it. No errors spit out either, so I am at a loss currently and any thoughts would be appreciated.

Tags : arcpy


Related Questions


Update Data Driven Pages Index layer via Python

Updated May 28, 2015 00:09 AM