Is there a way to extract parts of text from a dynamic text using xml tags? What I would like to do is to extract the number from an mxd file name and write it to a text box inside arcmap which is the caption. Example:
filename: Fig_3_Test.mxd
caption: <dyn type="document" property="name" split text start =3 end = 5/>
Thanks in advance
Nahide
Nahide,
This is an interesting question. It might be best asked in a different space since the GeoNet Help is for help with the geonet. Maybe move it to https://community.esri.com/groups/cartography-and-maps?sr=search&searchId=13fd9f1d-f437-462f-9374-b1... or https://community.esri.com/community/gis/managing-data?sr=search&searchId=28fe3f9f-473b-490a-963c-11... ?
Hi Nahide,
from a quick scan that sounds like Python 🙂
If I got it right you know the NAME of the element you want to fill, or can create one - then you should be able to use the TextElement Class. Dont think you can just use dynamic text.
Sure - you have to get the string part. If the document name has a structure as you say, something like this should do:
import arcpy,os
mxd = arcpy.mapping.MapDocument("CURRENT")
#do this in two lines - safe bet if Path can contain additional underscores
theName= str(mxd.filePath.split(os.sep)[-1:])
# now extract the number from the mxd-name
theTitle = str(theName.split("_")[-2]) #I assume a logic of _Number_ here
# and given you have an element called map title ...
elm = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapTitle")[0]
# set the text
elm.text = TheTitle
arcpy.RefreshActiveView()
Hi Günter:
I thought so too. But I wanted try my luck to see if anybody was able to do something like that through XML tags. I did something different in the end. I used the dynamic txt tag field for the figure numbers and when they change the figure numbers, which they will, I will do something like this:
for mxd in MXDList:
fileName = os.path.splitext(os.path.basename(mxd))[0]
figNum = str(fileName.split("_") [-2]
InMxd = arcpy.mapping.MapDocument(mxd)
InMxd.tags = figNum
InMXD. save
There you go! 🙂 Thanks for commenting again. Have fun! Guenter