Return character string from dynamic text?

402
1
05-22-2014 05:43 PM
JamesPaull
New Contributor III
Hi,

Is there a way to use to dynamic text to return a number of characters from a different dynamic text string in the same map document?

For example the title of my mxd might be 00051_BaseMap
I'd like to return the first five characters of this string dynamically so that I could have:

File Name: 00051_BaseMap
Project Number: 00051

Ie the project number is drawn out of the file name dynamic text string.

Thanks,
Tags (2)
0 Kudos
1 Reply
JimCousins
MVP Regular Contributor
I do not see a way to do it within the text box.
You could give the text element a name, and then access that text element within a python script and change it with string / list functions.
I use the following snippet to alter  a text element in my layout view:
for el in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","SSPA_Tag"):
            ToPoint = string.find(el.text,"_",5)
            el.text = "SSPA_" + bkmk.name + "_" + ChemName + "_" + Today.strftime("%m/%d/%Y")
            OutText = el.text


You could similarly use el.txt = el.text[:5] to return the first 5 characters.
Best Regards,
Jim
0 Kudos