Select to view content in your preferred language

Changing data source of layer in ArcGIS Pro Project using ArcPy

Jump to solution
12-21-2021 02:54 PM
Occasional Contributor

I have an ArcGIS Pro Project containing layers that have shapefiles as sources. I wrote a script using ArcPy to convert this data to File Geodatabases. Everything works fine here without any issues. 

The next step I want to take is replace the data sources of the same layers that I exported, so that they will be referencing the new file location in the File GDB. The best (and only?) way to replace the data source and dataset name is to use Layer.replaceDataSource . But when I use this Layer method, I get this error: 


AttributeError: 'Layer' object has no attribute 'replaceDataSource'


This is because replaceDataSource is a method found only in arcpy.mapping's Layer class. In other words, I'd need to use an ArcMap map document to utilize this method, instead of Pro. Is there a way to do this using library? Are there any other ways to achieve what I'm trying to do in ArcGIS Pro with ArcPy?

Thank you for the help!

Application Developer, GeoMarvel
Tags (3)
0 Kudos
11 Replies
MVP Esteemed Contributor

apparently not right enough

... sort of retired...
0 Kudos
New Contributor

Any timeline on when the `.save()` function will be repaired?

0 Kudos