Discussion created by Tonyalmeida on Mar 5, 2013
Latest reply on Mar 8, 2013 by jbarrette-esristaff
I have mxd i work on for different cases, but have the the same layers. The script i am working on needs to update the "Subject_Property" layer data source. I am having trouble getting this to work.

The script will search for a text in the "DXF_TEXT" filed and export it out to the location of the mxd. The mxd already has the layer "SUBJECT_PROPERTY" but i need to get it to update the mxd's "SUBJECT_PROPERTY" with the one that was searched and exported,  don't needed added to the current mxd. hopefully this makes sense.

Here is the code i have so far. Any help would be gratefully appreciated.
import arcpy, string, os

arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "TAXLOTS")[0]

arcpy.env.workspace = os.path.dirname(mxd.filePath)
wp = os.path.dirname(mxd.filePath)

value = arcpy.GetParameterAsText(0)
if value == "#" or value == "":
    value = None
if value:
    arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "\"DXF_TEXT\" = '" + str(value) +"'")
    arcpy.AddError("no value")
df.extent = lyr.getSelectedExtent()
df.scale = 7000

if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:

   arcpy.Select_analysis("TAXLOTS", "SUBJECT_PROPERTY")

#del mxd
#mxd = arcpy.mapping.MapDocument("CURRENT")
#lyr = arcpy.mapping.ListLayers(mxd, "SUBJECT_PROPERTY")[0]
lyrpath = lyr.workspacePath
data_path = os.path.dirname(lyrpath)

lyr.replaceDataSource(data_path, "SHAPEFILE_WORKSPACE", SP, True )