Select to view content in your preferred language

copy all data from an mxd

846
8
09-27-2010 07:09 AM
GregFiske
Regular Contributor
Hi,

I've got a complex MXD that is linked to various data throughout our network.  I'd like to write a python script that'll step through each layer in the MXD and copy it's data source to an output directory so I can burn all this data to a DVD for sharing.  Does anyone have some example arcpy code that they're willing to share?  Any advice will also be greatly appreciated.

thanks,

Greg
0 Kudos
8 Replies
JeffMoulds
Esri Contributor
Are you using 10? If so, you can do this without writing code - just create a map package. You can share the map package - its a portable file containing a MXD and all the data.
0 Kudos
GregFiske
Regular Contributor
Thanks Jeff.  Map Packages are awesome.  However, the recipient of my data uses ArcGIS version 9.3
0 Kudos
JeffMoulds
Esri Contributor
Are you at 10 though? You can take the MXD that is embedded in the MPK and save it to 9.3. You can also copy all the data from the geodatabases in the MPK to 9.3 geodatabases. The 9.3 MXD will still be portable because it has relative paths to the data.
0 Kudos
GregFiske
Regular Contributor
Jeff - I am using 10 and this is a great solution.  You the man.  Thanks.
0 Kudos
DonovanCameron
Deactivated User
How would you do this in ArcGIS 9.x? I read above that a code may do this?
0 Kudos
JeffBarrette
Esri Regular Contributor
This is a perfect application of the arcpy.mapping scripting environment.

You could loop through a folder of mxds and simply execute the following code.

Mxd=arcpy.mapping.MapDocument(path to mxd)
Mxd.description = "whatever"

there are some great sample tools/scripts available to help you.

Go to the resource center and do a search on

arcpy.mapping sample script tools

Jeff
0 Kudos
KieranSmith
Emerging Contributor
I have a couple of queries on this -

We have data that's stored in SDE and variety of CAD files. For SDE data, the MPK saves the whole file (which can be a problem because we want to store more data in SDE and our geographic regions can be provincial up to continental in size). Is there a way of saving only a specified area of interest?

With CAD, the data is by defauly unprojected. I've not had any luck defining a projection after getting errors with the validation tool. Any suggestions for getting around this?

Thanks
Kieran
0 Kudos
JeffBarrette
Esri Regular Contributor
Just a note - this thread is getting really fragmented.  It is best to create a new thread when the topic is being changed.

Here is a response to Christopher.  This following code updates the mxd.description

import arcpy, os
parentDir = r"C:\Demos\MapAutomation\SaveToPDF"
for (path, dirs, files) in os.walk(parentDir):
>>for filename in files:
>>>>if filename.lower().endswith(".mxd"):
>>>>>>mxd = arcpy.mapping.MapDocument(os.path.join(path, filename))
>>>>>>print mxd.filePath
>>>>>>mxd.description = "python test"
>>>>>>mxd.save()

Get rid of the ">>" symbols.

Hope this helps,
Jeff
0 Kudos