Hi, I'm looking to create a python script that will update a folder of mxds together. I have designated 6 TEXT_ELEMENTS in my titleblock to be updated using arcpy.GetParameterAsText() but will just use 1 for this question.
Below is my text for updating the text element if i were to only update one .mxd which as the top line says only edits the current .mxd that is open.
thisMap = arcpy.mapping.MapDocument("CURRENT") myDF = arcpy.mapping.ListDataFrames(thisMap) [0] myLayers = arcpy.mapping.ListLayers(myDF) newProjectTitle = arcpy.GetParameterAsText(0) myElements = arcpy.mapping.ListLayoutElements(thisMap, "TEXT_ELEMENT") for element in myElements: if element.name == "ProjectTitle": element.text = newProjectTitle arcpy.RefreshActiveView()
Then using a script in a custom toolbox, i can input the new Project title, and it update the MXD. (not very useful yet as i could just click on the text element itself and update it manually)
However i would like to take it further and update not just the current .mxd, but all my .mxds in a specified folder and (using path = arcpy.GetParameterAsText(0))
It will save ample amounts of time as there are projects where i will need to manually open x amount of .mxds to rename a Text element in all of them that has been incorrectly named.
I was wondering if anyone could help me with the python code as im quite new to python and don't know what i am doing:
1) specifying the folder to open using path = arcpy.GetParameterAsText
2) creating a list of all the .mxds in said folder (like below? not sure if this is the best method)
iteLog=open(path+"\FileListLog.txt","w") for fileName in os.listdir(path): fullPath = os.path.join(path, fileName) if os.path.isfile(fullPath): basename, extension = os.path.splitext(fullPath) if extension == ".mxd": writeLog.write(fullPath+"\n") mxd = arcpy.mapping.MapDocument(fullPath) print fileName + "\n" del mxd print "Done" writeLog.close()
3) specifying the text_element(s) to be updated
4) cycling through (via the script) each .mxd in the list and updating the specified text_element, then saving, closing and opening the next on the list. (this would be the main part im confused with)
Thanks in advance and let me know if i haven't provided enough information!
Stef