I'm trying to turn off visibility of a text element called "Draft" on 20 layouts in in an aprx. The script runs without errors, but the element doesn't get turned off on any of the pages.
import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Users\kberg\Documents\DataGapEvaluation.aprx")
for lyt in aprx.listLayouts():
for elm in lyt.listElements('TEXT_ELEMENT'):
if elm.text == "Draft":
elm.visible = False
aprx.save()
del aprx
Solved! Go to Solution.
It was saving in the code I was referring to. That seems to be the case in the code samples in the links. And if you have Pro open when you are using your code, you should be using "CURRENT" rather than a path to the aprx
do you save the aprx?
TextElement—ArcPy | Documentation
or are you hoping this does it interactively with the project open?
Yes, I've run the code, saved, closed, and restarted. Still doesn't turn off the element.
It was saving in the code I was referring to. That seems to be the case in the code samples in the links. And if you have Pro open when you are using your code, you should be using "CURRENT" rather than a path to the aprx
Something must've been acting weird with referring to the path vs. "CURRENT". Changing that fixed it. Thanks, Dan Patterson!
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
for lyt in aprx.listLayouts():
for elm in lyt.listElements('TEXT_ELEMENT'):
if elm.text == "DRAFT":
elm.visible = False
aprx.save()
del aprx