Select to view content in your preferred language

Can't figure out layer.ReplaceDataSource

430
0
01-24-2019 10:58 AM
deleted-user-xWsm0i8XW8uH
Deactivated User

Can't figure this one out.  I'm trying to replace a layer's datasource based on a user-input parameter (not shown in the code snippet).  I know the SDE path that gets created (BasinPath variable) is correct because I've tested it using other try/except statements.  Anyone familiar with this tool?  I'm using 10.6.  The try/except statement beginning on line 13 is the part that isn't working.

def zoomTo(info, bas):
    doc = arcpy.mapping.MapDocument("Current")
    dataFrame = arcpy.mapping.ListDataFrames(doc)[0]
    if waterRight:
        MapLayers = arcpy.mapping.ListLayers(doc,"statewide_irr",dataFrame)
        Layer = MapLayers[0]
        DNRPrd = "D:\\WID\\WID_SDE.sde"
        IRR = DNRPrd + "\\" + "WID_SDE.Irr"
        BasinPath = IRR + "\\" + "WID_SDE.Irr_" + str(bas)
        for layr in arcpy.mapping.ListLayers(dataFrame):
            if layr.name == "statewide_irr":
                arcpy.AddMessage(BasinPath)
                try:
                    layr.replaceDataSource(BasinPath, "SDE_WORKSPACE", "statewide_irr", True)
                except:
                    errorMsg = "Error in dataSourceReplace"
                    pythonaddins.MessageBox(errorMsg, 'Shucks!', 0)
                    print(errorMsg)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Replies