Replacing layer SDE connection

المشرف العام

Administrator
طاقم الإدارة
Please forgive me, as I am very new to using Python...

I have an MXD with all of my layer files in it. They are grouped by category etc. Each layer file references a dataset within my SDE. My SDE has two different connections, Admin and View. Admin allows administration of all feature classes. View is a select only connection.

All of my layers should be connected to feature classes in the View SDE connection. However I have over 70 layers which reference the Admin SDE connection. How do I change this using Python. I do not want to manually change the source SDE connection and then save a new layer.

Would it also be possible to overwrite the layer file using its current file information and location?

I have tried the following bits of code but no luck...

import arcpymxd = arcpy.mapping.MapDocument("CURRENT")for lyr in arcpy.mapping.ListLayers(mxd): lyr.replaceDataSource(r"C:\Users\x939062\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\MMO_View.sde", "SDE_WORKSPACE",,"False")I have also tried the following, but again no luck...

import arcpymxd = arcpy.mapping.MapDocument("CURRENT")for lyr in arcpy.mapping.ListLayers(mxd): lyr.findandreplaceworkspacepath (r"C:\Users\x939062\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\MMO_Admin.sde", r"C:\Users\x939062\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\MMO_View.sde")Any help would be greatly appreciated. Thanks



أكثر...
 
أعلى