I would like to selectively choose my MXD documents through the multivalue or filter parameter in the toolbox.
From the selected MXD's the user should be able to replace text and re-save the document.
I can get it to work on a series of unselected MXD documents located in a specific folder, but I need to be able to choose those MXD's.
Essentially the question is how do I integrate the multi-value parameter into the code?
import arcpy
import os
inMXD = arcpy.GetParameterAsText(0) #toolbox parameter workspace
#prepare for multivalue toolbox parameter
#ListInMXD = inMXD.split(";")
#set old and new text variables
OldText = arcpy.GetParameterAsText(1)
NewText = arcpy.GetParameterAsText(2)
#THis is where it should loop through the ListInMXD
for file in ListInMXD:
filePath = os.path.join(ListInMXD, file)
mxd = arcpy.mapping.MapDocument(filePath)
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.text == OldText:
elm.text = NewText
mxd.save()
With PolyGeo's answer I was able successfully to re-write the code as follows:
import arcpy
import os
mxdString = arcpy.GetParameterAsText(0) #toolbox parameter workspace
#prepare for multivalue toolbox parameter
mxdList = mxdString.split(";")
arcpy.AddMessage(mxdList)
#set old and new text variables
OldText = arcpy.GetParameterAsText(1)
NewText = arcpy.GetParameterAsText(2)
#THis is where it should loop through the ListInMXD
for mxdItem in mxdList:
mxd = arcpy.mapping.MapDocument(mxdItem.strip("'")) #this little snippet came from https://geonet.esri.com/thread/67229
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.text == OldText:
elm.text = NewText
mxd.save()
del mxd