Select to view content in your preferred language

findAndReplaceWorkspacePaths is crashing Python script

3060
7
04-18-2012 09:46 AM
WaiChan1
Deactivated User
I am trying to change the layers data source in a map document, from the current SDE connection to the new SDE connection, using Python. I had used the example given in the ArcGIS Desktop Help 10.0 (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000004p000000), but the script keep crashing when it gets to the mxd.findAndReplaceWorkspacePaths line.

Here is the code. Any suggestion will be greatly appreciated. Thank you.

import arcpy
mxd = arcpy.mapping.MapDocument(r"I:\RepointMXD.mxd")
mxd.findAndReplaceWorkspacePaths(r"I:\current_sde.sde", r"I:\new_sde.sde")
mxd.saveACopy(r"I:\RepointMXD_new.mxd")
del mxd
Tags (2)
0 Kudos
7 Replies
RyanForbes1
Occasional Contributor
Does it hard crash or does it provide you with some kind of error?
0 Kudos
WaiChan1
Deactivated User
I am using Windows 7 64-bit. After running the code, all it gives is a standard "PyWin 32 has stopped working." message, with the options to close the program or debug the program. Either option will make Python closes itself.
0 Kudos
RyanForbes1
Occasional Contributor
What service pack are you using?  If you're still pre 4 you could try updating.

Do you have an image service layer?  I found evidence that findAndReplaceWorkspacePath will crash if there is an image service layer -- ( http://support.esri.com/en/bugs/nimbus/TklNMDYwMzE1 ) not sure if it is related or if it was ever fix't.
0 Kudos
WaiChan1
Deactivated User
Thank you for pointing that out. I took out the image service, and the script ran with no problem. However, it did not replace the SDE workspace in the layer files, like it's supposed to do. The layers in the new MXD still points to the current SDE.
0 Kudos
JoeFlannery
Honored Contributor
I can confirm that findAndReplaceWorkspacePaths script does run with image/background services in the map TOC in ArcGIS for Desktop version 10.1.
See: http://forums.arcgis.com/threads/60553-Find-and-Replace-Workspace-Path-not-working?highlight=findAnd...

However, I am getting the same results as Wai Chan. The script completes, but does NOT change the file paths to geodatabases.


import arcpy, os

# Local variables
oldSDE = r"M:\Clients\M-O\ABC\_ArcGIS\2012\06\TestingRepath\SQL01\\"
newSDE = r"M:\Clients\M-O\ABC\_ArcGIS\2012\06\TestingRepath\SQL02\\"
mapDoc = r"M:\Clients\M-O\ABC\_ArcGIS\2012\06\TestingRepath\_Map02_wBackgrounds.mxd"

print "Define MapDocument Parameter"
mxd = arcpy.mapping.MapDocument(mapDoc)

print "Start FindAndReplace Process"
mxd.findAndReplaceWorkspacePaths(oldSDE, newSDE)

print "Start saveAcopy Process"
mxd.saveACopy(r"M:\Clients\M-O\ABC\_ArcGIS\2012\06\TestingRepath\_Map02_NEW_TenOne.mxd")

print "Done"

del arcpy, oldSDE, newSDE, mapDoc, mxd



UPDATE - found the problem
I removed the "\\" at the ends of the oldSDE and newSDE variable file paths and now the repath script works.
0 Kudos
WaiChan1
Deactivated User
jrflannery,

For the oldSDE and newSDE parameters, I thought they were supposed to be sde connection files (*.sde). What connection files are SQL01 and SQL02?

Thank you!
0 Kudos
JoeFlannery
Honored Contributor
Mr. Chan:  Good question.  My sample for testing, described in earlier posts, was using two file geodatabases (SQL01 & SQL02).  Sorry for the confusion.  I have not tried it against real SQL geodatabases, yet.
0 Kudos