Select to view content in your preferred language

Toggle Text Element Visibility in ArcGIS Pro

947
4
Jump to solution
02-25-2020 08:06 AM
KateBerg2
New Contributor III

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
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

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

View solution in original post

4 Replies
DanPatterson_Retired
MVP Emeritus

do you save the aprx?

TextElement—ArcPy | Documentation 

or are you hoping this does it interactively with the project open?

0 Kudos
KateBerg2
New Contributor III

Yes, I've run the code, saved, closed, and restarted. Still doesn't turn off the element.

0 Kudos
DanPatterson_Retired
MVP Emeritus

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

KateBerg2
New Contributor III

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‍‍‍‍‍‍‍‍
0 Kudos