Select to view content in your preferred language

Why does this Arcpy Script Execute - but Fail to Accomplish Objective

3960
3
Jump to solution
04-29-2015 09:33 AM
JamesLabate
New Contributor II

Hello,

I'm trying to simply change the workspace paths for a folder full of mxds at a time.I came across this script which executes in the Python Window of Arcmaap without an error message being thrown. Unfortunately, when I open an mxd in the folder to check results nothing has changed - it still points to the old workspace.

The workspace I am trying to have the Arcpy script repoint to is an SDE Workspace being served by Sequal Server Express. I read that there are "known issues" with SSExpress. Am I doomed?

Other Arcpy attempts to just swap the workspaces of a single mxd - also repointing to SDE have had some success - if "saveACopy"

Any assistance is appreciated. Here's the script that doesn't error out or accomplish the task either. Thanks in advance - Jim

import arcpy, os

>>> folderPath = r"G:\Projects\Utilities"

>>> for filename in os.listdir(folderPath):

...     fullpath = os.path.join(folderPath, filename)

...     if os.path.isfile(fullpath):

...         basename, extension = os.path.splitext(fullpath)

...         if extension.lower() == ".mxd":

...             mxd = arcpy.mapping.MapDocument(fullpath)

...             mxd.findAndReplaceWorkspacePaths(r"N:\SDE_Backup_2014\Shapefiles.gdb", r"Database Connections\Connection to usmasvgdpw01.sde")

...             mxd.save()

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

From the help files

Would this not be your scenario?

MapDocument.replaceWorkspaces(old_workspace_path, old_workspace_type, new_workspace_path, new_workspace_type, {validate})

  • The replaceWorkspaces method on the MapDocument object is similar to the  findAndReplaceWorkspacePaths method but also allows you to switch from one workspace type to another (for example, personal geodatabase to file geodatabase).  Generally, this method  works on one workspace type at a time. If more than one workspace type needs to be replaced, use the method multiple times for each workspace type.  See the "General usage notes" section below for other alternative usages.

View solution in original post

3 Replies
DanPatterson_Retired
MVP Emeritus

From the help files

Would this not be your scenario?

MapDocument.replaceWorkspaces(old_workspace_path, old_workspace_type, new_workspace_path, new_workspace_type, {validate})

  • The replaceWorkspaces method on the MapDocument object is similar to the  findAndReplaceWorkspacePaths method but also allows you to switch from one workspace type to another (for example, personal geodatabase to file geodatabase).  Generally, this method  works on one workspace type at a time. If more than one workspace type needs to be replaced, use the method multiple times for each workspace type.  See the "General usage notes" section below for other alternative usages.
JamesLabate
New Contributor II

Thanks Dan,

That method did work - strange side effect though - the mxds page size defaulted to leter when they were all originally 11X17. Anything in the code causing that?

Thanks again,

Jim

0 Kudos
DanPatterson_Retired
MVP Emeritus

maybe it uses a default template during the transition, if so, I suppose you can set it somewhere before running the script

0 Kudos