Select to view content in your preferred language

Python Script to find data sources

746
2
04-01-2014 06:32 AM
JakeGalyon
Regular Contributor
We are in the process of cleaning up a network drive and began loading shapefiles into SDE.  Some of the shapefiles that we are migrating are sourced to various mxd's.  Is there a script/tool out there that we can run that will tell us what shapefile is sourced to an mxd?  That way we could determine if we need to migrate that file, and also avoid potentially deleting data that is being used?  I would appreciate any input.  Thanks!

Jake
Tags (2)
0 Kudos
2 Replies
MikeMacRae
Frequent Contributor
It depends on which version of ArcGIS you are running, but at 10.0 and above, you can grab the datasource via the mapping module. Your best bet is to flip through this help page and look at the code snippits and decide which approach you need.:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000004p000000

Also, if you're just looking to read in the datasource of each layer, you can look at the layer object library and write a script to flip through your mxd's and print out the mxd name, each dataframe within the mxd, each layer within the dataframe and its associated datasource.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/
0 Kudos
MichaelVolz
Esteemed Contributor
I would suggest trying to use the replaceDataSource method to convert from a shapefile to SDE, although I'm not 100% this transfer will work as you would need to test it first.

If replaceDataSource does not work, then I would suggest using the UpdateLayer method which would definitely work, but you would need to have the lyr files preprocessed and if different mxds have different symbology for the same shapefile you would either need to create multiple lyr files for the same shapefile source or have all new SDE layers have the same symbology which your end users might object to.

I would also run the script with logging to get an inventory of how many layers you will need to resource before you actually run the tool to process layers on the production mxds.

You could also use the Set Data Source(s) in ArcCatalog on each mxd and resource the shapefiles with that method (This would avoid having to do any programming but could be time consuming if you are dealing with at least 100 mxds).
0 Kudos