Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to do something quite simple but its not working. I want my python script to change all of the layers that point to the same datasource (a point shapefile) to another point shapefile. replaceDataSource seems to be the methods but when I run this:

for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.dataSource == r"X:\filepath\folder\points.shp":
            print lyr.dataSource
            lyr.replaceDataSource(r"\\main.glb.corp.local\E-GB$\Home\AB\4\J022414\Documents\ArcGIS", 'SHAPEFILE_WORKSPACE', "ismage_template_P.shp")
            print "data replaced"

i get "Runtime error type 'exceptions.ValueError'>: Layer: Unexpected error" when I run this. It prints the data source but doesnt print "data replaced" so it looks like the problem is on the lyr.replacedatasource line

Has anyone had this problem before, or should I be using a different method?

share|improve this question
up vote 1 down vote accepted

Your lyr.replaceDataSource already knows that it is working with a SHAPEFILE_WORKSPACE and so it does not need ".shp " (which instead upsets it).

If you leave it off then I think your code will work.

share|improve this answer
Thanks, that seems to have worked, I have run into another problem thought. I dont know if its related "Runtime error <type 'exceptions.AttributeError'>: LayerObject: Get attribute dataSource does not exist". Any idea? – whatahitson Mar 28 '14 at 12:49
Oh never mind I fixed it by adding "if lyr.supports("DATASOURCE"):" – whatahitson Mar 28 '14 at 13:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.