Tonyalmeida

Updating two or more features data source

Discussion created by Tonyalmeida on Nov 4, 2013
Latest reply on Nov 5, 2013 by Tonyalmeida
I am trying to update 2 (for the moment) feature data source for but when i run the script the "NOTIFBUF1" layer disappears.
I don't know why? This script will eventually have a arcpy.GetParameterAsText(0) for the "Subject_property". But i would like to figure out how to change 2 data source in the same mxd first.

import arcpy
import os

arcpy.env.overwriteOutput = True
arcpy.env.qualifiedFieldNames = False

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
arcpy.env.workspace = os.path.dirname(mxd.filePath)
wp = os.path.dirname(mxd.filePath)

for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.supports("DATASOURCE"):
        if lyr.name == "SUBJECT_PROPERTY":           
            lyr.replaceDataSource(wp, "SHAPEFILE_WORKSPACE", "SUBJECT_PROPERTY", "")

del mxd
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "NOTIFBUF1")[0]

SP = "SUBJECT_PROPERTY"
arcpy.MultipleRingBuffer_analysis(SP, "1_2",[1,2],"Miles","ToBufDist","ALL" )
arcpy.MultipleRingBuffer_analysis(SP, "NOTIFBUF1",[600],"Feet","ToBufDist","ALL", "FULL")


for df in arcpy.mapping.ListDataFrames(mxd):
        for lyr in arcpy.mapping.ListLayers(mxd, "NOTIFBUF1", df):
                lyr.replaceDataSource(wp, "SHAPEFILE_WORKSPACE", lyr.datasetName, False)

arcpy.RefreshTOC()
arcpy.RefreshActiveView()


So any help would be great.

Thanks.

Outcomes