I think that ArcGIS is reading the \n as a new line within the text string instead of reading the document path as pure text.
mxd = arcpy.mapping.MapDocument("CURRENT") mxd.filePath # u'C:\\GIS\\newFolder\\bugtest102.mxd' el = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","MXDPath")[0] el.text # u'Document Path: <dyn type="document" property="path" />' el.text = mxd.filePath.replace("\\","/") # use the universal path separator supported by Windows for POSIX compliance el.text # u'C:/GIS/newFolder/bugtest102.mxd' mxd.save() del mxd
I have a somewhat related question that I am hoping someone can help me with. I was using dynamic text to create a header with the name of my mxd. I have one character at the end of the name of the mxd that I do not want to display in the header (renaming the mxd is not an option). From what I have read, there is no way to remove a character using dynamic text; however, I have read that I can use Python to insert the name of the mxd as text and then remove that last character. I have been searchign and searching the Web. Is there someone who knows how to do this by chance?