Select to view content in your preferred language

"findAndReplaceWorkspacePaths" not working

807
2
06-10-2011 03:45 AM
ZackBartlett
Regular Contributor
I have a Python script that scans a folder for MXDs, then replaces broken workspace paths with correct workspace paths.  The folder of MXDs is quite large, so to make things easier/faster for testing purposes, I've made a copy of one of the MXDs in a subfolder and worked with that instead.  However, my script does not appear to be fixing the workspace paths.

I've tripled checked that I've entered pathnames correctly (for both the broken and correct paths).  I've actually copied and pasted the pathnames, so they have to be working.  And I've copied and pasted those pathnames back into ArcCatalog to be sure they point to actual files.  Nonetheless, the paths in the MXD aren't changing.

I tried with the workspace paths set to relative, but that didn't work either.

The odd thing is, I did a quick test this morning with an MXD and a shapefile at the base of my C: drive (changing the shapefile's path from C:/test to C:/test1) and it worked fine.

Also, when the script reaches the line of code that saves the MXD, the modified date in Windows Explorer updates.  Any help here would be appreciated.  I've attached the code block.

Thanks

-Zack
Tags (2)
0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
In your code, you are specifying the path and feature class.  You will just need to specify the path.

Ex:

brkn05 = r"T:\JOBS\1032385\Project Administration\Data In\Data_Audit_2011\Sikumiut\Raw_Data_Delivery_June12011\GDB - Current to March 2010\Project Figures\Project Discipline\Freshwater_Environment.gdb\FrshWtrEnvr_Features"

Change this to:

brkn05 = r"T:\JOBS\1032385\Project Administration\Data In\Data_Audit_2011\Sikumiut\Raw_Data_Delivery_June12011\GDB - Current to March 2010\Project Figures\Project Discipline\Freshwater_Environment.gdb"


You can also simplify your code using the glob module.  Ex:

import arcpy, os, glob

arcpy.env.Workspace = r"T:\JOBS\1032385\Project Administration\Data In\Data_Audit_2011\Sikumiut\Raw_Data_Delivery_June12011\GDB - Current to March 2010\Project Figures\Figures MXD\test"

folder_path = arcpy.env.Workspace

# Create a list of broken workspace paths and assign to variables
brkn05 = r"T:\JOBS\1032385\Project Administration\Data In\Data_Audit_2011\Sikumiut\Raw_Data_Delivery_June12011\GDB - Current to March 2010\Project Figures\Project Discipline\Freshwater_Environment.gdb\FrshWtrEnvr_Features"

# Create a list of correct workspace paths and assign to variables
corr05 = r"T:\JOBS\1032385\Project Discipline\Freshwater_Environment.gdb\FrshWtrEnvr_Features"

for file in glob.glob(folder_path + "\*.mxd"):
     mxd = arcpy.mapping.MapDocument(file)
     mxd.findAndReplaceWorkspacePaths(brkn05, corr05, true)
     mxd.save()

del mxd

print "Be sure to check MXDs to ensure paths have been properly assigned."
0 Kudos
ZackBartlett
Regular Contributor
I took your suggestions.  They worked. I am forever indebted to you!!!
0 Kudos