Using python to change layer source

78 views
Skip to first unread message

Herb.Sc...@gov.bc.ca

unread,
Apr 28, 2014, 12:26:31 PM4/28/14
to geop...@googlegroups.com
Seems like a simple thing to do, but I can't get it to work. I've tried 'findAndReplaceWorkspacePaths', 'replaceWorkspaces', 'lyr.replaceDataSource', etc. These are not broken links I'm trying to change, just need to change to a different source. Code seems to run okay, no error messages, but source never changes in the layers. I'm trying to change from one personal geodatabase to another.
 
Yes, I know what you're thinking, but I need the personal geodatabase for now because I need to work with it in ACCESS.
 
Help me Obiwan Kenobi, you're my only hope ...
 
Here is the part of code in question ...
 
# this didn't work
# this didn't work
 
# this isn't working either
for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.supports("DATASOURCE"):
        if lyr.dataSource == r"\\bctsdata.bcgov\tko_root\Data_Library\Analysis\ECA\test.mdb\Sub_Basins":
            gp.AddMessage("We're on Sub Basins ")
            lyr.replaceDataSource(r"\\bctsdata.bcgov\tko_root\Data_Library\Analysis\ECA\Boundary_FT\ECAState\ver_2014\ECA_State_ver_2014.mdb", "ACCESS_WORKSPACE", "Sub_Basins")
           
 
Reply all
Reply to author
Forward
0 new messages