I am trying to write some code that will get the current workspace name and if it matches a particular datasource path, it will re-path the SDE layers to the new database. Initially I had the code working by just running the re-source code on ArcMap startup but this caused problems with the MXD's "Store relative pathnames" option in MXD and would turn it off. The problem I am having is that I am not sure how to tell it "if the workspace is "blah.sde" then only run the resource code. The MXD's connect to 3 SDE's. Here is what I have:
import arcpy
import pythonaddins
from arcpy import env
class ExtensionClass1(object):
"""Implementation for python_addin.extension2 (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in
this class.
self.enabled = True
def startup(self):
mxd = arcpy.mapping.MapDocument("CURRENT")
if arcpy.env.workspace = r"C:\ArcGIS\blah.sde":
mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\blah.sde",
r"C:\ArcGIS_10.3.1\blah.sde")
mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\blah2.sde",
r"C:\ArcGIS_10.3.1\blah2.sde")
mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\blah3.sde",
r"C:\ArcGIS_10.3.1\blah3.sde")
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
def openDocument(self):
mxd = arcpy.mapping.MapDocument("CURRENT")
if arcpy.env.workspace = r"C:\ArcGIS\blah.sde":
mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\blah.sde",
r"C:\ArcGIS_10.3.1\blah.sde")
mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\blah2.sde",
r"C:\ArcGIS_10.3.1\blah2.sde")
mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\blah3.sde",
r"C:\ArcGIS_10.3.1\blah3.sde")
arcpy.RefreshActiveView()
arcpy.RefreshTOC()