I'm having the same issue when running my python script. It connects the layers fine, then immediately removes them.Is this a known bug?
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") newSdePath = r"Database Connections\My Connection.sde" for df in arcpy.mapping.ListDataFrames(mxd): for lyr in arcpy.mapping.ListLayers(mxd, "", df): lyr.replaceDataSource(newSdePath, "SDE_WORKSPACE", lyr.datasetName, False) arcpy.RefreshTOC() arcpy.RefreshActiveView() mxd.save() del mxd
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") newSdePath = r"Database Connections\My Connection.sde" for df in arcpy.mapping.ListDataFrames(mxd): for lyr in arcpy.mapping.ListLayers(mxd, "", df): if (lyr.supports("DATASOURCE") and lyr.supports("datasetName")): lyr.replaceDataSource(newSdePath, "SDE_WORKSPACE", lyr.datasetName, False) arcpy.RefreshTOC() arcpy.RefreshActiveView() mxd.save() del mxd
import arcpy, os mxd = arcpy.mapping.MapDocument("CURRENT") newSdePath = r"Database Connections\My Connection.sde" oldSdePath = r"Database Connections\My Old Connection.sde" for df in arcpy.mapping.ListDataFrames(mxd): for lyr in arcpy.mapping.ListLayers(mxd, "", df): if (lyr.supports("DATASOURCE") and lyr.supports("datasetName")): tempDataSetPath, tempDataSet = os.path.split(lyr.dataSource) tempDataSetPath, tempDataSetClass = os.path.split(tempDataSetPath) if lyr.dataSource == os.path.join(oldSdePath, tempDataSetClass, lyr.datasetName): lyr.replaceDataSource(newSdePath, "SDE_WORKSPACE", lyr.datasetName, False) arcpy.RefreshTOC() arcpy.RefreshActiveView() mxd.save() del mxd
Hi Christian,as far as I understood the "CURRENT" option is basically meant to be used from within the python-Window.Try to parse the full mxd-Path as an argument into your script and make the document line get thatmxd = arcpy.mapping.MapDocument(r"C:\temp\xxtest.mxd") Havent tried but its worth a try!RegardsGuenter
mxd = arcpy.mapping.MapDocument(r"C:\temp\xxtest.mxd")
saveACopy (file_name, {version})
dateSaved
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.