trying to change text with ListLayoutElements,

1039
5
Jump to solution
01-19-2017 08:15 AM
petegillard
New Contributor III

it only works searcing with actual string. can't find the text when i use  * . changing date and path strings, so they're not all the same.

ex.

for dA in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
    
     if dA.text == 'DATE: 10/10/2011': 
         dA.text = 'Date: <dyn type="date" format=""/>'  THIS WORKS

for fp in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
        if fp.text == 'FILE: *': 
        fp.text = 'Document Path: <dyn type="document" property="path"/>' THIS DOESN'T WORK

Thanks in advance for any ideas.

Pete

0 Kudos
1 Solution

Accepted Solutions
IanMurray
Frequent Contributor

Maybe try the reverse logic to this. 

Using the in operater you can check if a string contains a subtring, that way you don't need a wildcard

for fp in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
        if 'FILE: ' in fp.text: 
              fp.text = 'Document Path: <dyn type="document" property="path"/>'

http://stackoverflow.com/questions/3437059/does-python-have-a-string-contains-substring-method

View solution in original post

5 Replies
IanMurray
Frequent Contributor

Maybe try the reverse logic to this. 

Using the in operater you can check if a string contains a subtring, that way you don't need a wildcard

for fp in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
        if 'FILE: ' in fp.text: 
              fp.text = 'Document Path: <dyn type="document" property="path"/>'

http://stackoverflow.com/questions/3437059/does-python-have-a-string-contains-substring-method

petegillard
New Contributor III

Thanks to BOTH responses. It worked beautifully!!

0 Kudos
DarrenWiens2
MVP Honored Contributor

... or:

if fp.text.startswith('FILE: '): 
petegillard
New Contributor III

Thanks to BOTH responses. It worked beautifully!!

0 Kudos
IanMurray
Frequent Contributor

Can you please mark the question as answered?

0 Kudos