Python Addin extension stops relative paths from working

137
2
05-04-2018 02:45 AM
DazSalar
New Contributor

Hi. 

I have python code extension that runs on startup. The MXD has "store relative Paths" turned on by default. The script works well and does what it has to do. However every time the script runs it stops the ""Store relative paths" in the MXD from working and breaks the link to the local gdb. The script simply resources some of the layers in the MXD to the new SDE database. So not sure why its interfering with the "Store relative paths" for the local gdb. If i remove the extension and my code is not running then Store relative paths work. I have made sure the data folder and MXD are in same location. I have inserted MXD.relativepaths = True but the script ignores it. I have checked the MXD properties when the script runs and there is a tick in the box so not sure if this is a bug in ArcMap? Any ideas?

import arcpy
import pythonaddins

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")
             mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\SDE1.sde",r"C:\ArcGIS_10.3.1\SDE1.sde")
              mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\SDE2.sde",r"C:\ArcGIS_10.3.1\SDE2.sde")
             mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\SDE3.sde",r"C:\ArcGIS_10.3.1\SDE3.sde")
             arcpy.RefreshActiveView()
             arcpy.RefreshTOC()
             mxd.relativepaths = True


    def openDocument(self):
           mxd = arcpy.mapping.MapDocument("CURRENT")
         mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\SDE1.sde",r"C:\ArcGIS_10.3.1\SDE1.sde")
         mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\SDE2.sde",r"C:\ArcGIS_10.3.1\SDE2.sde")
         mxd.findAndReplaceWorkspacePaths(r"C:\ArcGIS\SDE3.sde",r"C:\ArcGIS_10.3.1\SDE3.sde")
         arcpy.RefreshActiveView()
         arcpy.RefreshTOC()
         mxd.relativepaths = True‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
2 Replies
JoeBorgione
MVP Esteemed Contributor

Maybe put your mxd.relativepaths = 'TRUE' at the same level as import arcpy, outside of any defs or classes. (If you use the syntax highlighter when posting code, it makes it much easier to read and refer to line numbers....)

can't wait to retire....
0 Kudos
DazSalar
New Contributor

Hi Joe,

I tried that but it still does not work. When i copy and paste the data and mxd to another location it ignores it and tries to edit the database from where the data was copied from. Very bizarre. So when I copy the local gdb and MXD from C:/ drive to 😧 drive it still thinks the data is on C:/ However it resources the SDE layers like it is supposed to.

Regards

0 Kudos