2

I have a python code I'm running in ArcGIS 10.6 that replaces the data source path of all layers in the mxd with a new path. I'm trying to use a wildcard for the current workspace path as many layers in our template mxd have different data source paths.

The part of code in question is this line:

mxd.findAndReplaceWorkspacePaths(r"*", r"P:\JOBS\2018\18-9992\Drawings\GIS")

The r"*" doesn't seem to work as a wildcard.

Here is the full code:

# Importing necessary modules import arcpy, os # Setting path to mxd and Data Frame mxd = arcpy.mapping.MapDocument(r"CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "UTM_12")[0] #List layers and replace current path with new path for lyr in arcpy.mapping.ListLayers(mxd, "*", df): mxd.findAndReplaceWorkspacePaths(r"*", r"P:\JOBS\2018\18-9992\Drawings\GIS") #Delete any layers with broken links (no datasource) for lyr in arcpy.mapping.ListLayers(mxd, "*", df): if lyr.isBroken: arcpy.mapping.RemoveLayer(df, lyr) # Saving the mxd mxd.save() 
1
  • 2
    I think you can use lyr.workspacePath in the first parameter instead of the wildcard. Commented Mar 14, 2018 at 21:33

2 Answers 2

2

Using lyr.workspacePath worked as long as I used if lyr.isFeatureLayer to avoid groups layers and rasters.

0

Set the layer's workspace path directly instead of using findAndReplaceWorkspacePaths:

for lyr in arcpy.mapping.ListLayers(mxd, "*", df): if lyr.isFeatureLayer: lyr.workspacePath = r"P:\JOBS\2018\18-9992\Drawings\GIS" 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.