4

I have a python script which reads through all the mxd's in a folder and changes their properties from relative file paths to absolute file paths.

I now want to add a bit to the script to change the version of the mxd from 10.1 to 10.0.

I want the 10.0 mxd to be saved into a pre-defined folder.

The new mxd should have the same name as the original mxd. This is the bit I'm struggling with.

How do I get the name of the original mxd? (defined as basename in the code below). I'm assuming I need to use an arcpy.mapping function, but I'm completely stumped.

import arcpy, os
#workspace to search for MXDs
Workspace = r"C:\Testing\ImageMapperReplacement\LRM157"
arcpy.env.workspace = Workspace
#list map documents in folder
mxdList = arcpy.ListFiles("*.mxd")
#set relative path setting for each MXD in list.
for file in mxdList:
#set map document to change
filePath = os.path.join(Workspace, file)
mxd = arcpy.mapping.MapDocument(filePath)
#Get the file name
basename = ??????
#set relative paths property
mxd.relativePaths = False
#save map doucment change
mxd.saveACopy (r"C:\Testing\ImageMapperReplacement\LRM157\mxd2\\" + basename + ".mxd", {10.0})
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 24, 2013 at 12:18
1
  • 6
    You already have it. The mxd filename is your file variable. Note: you shouldn't use file as a variable as you're overriding the built in function Commented Sep 24, 2013 at 12:41

1 Answer 1

8

Ok, I've figured it out. Thanks Luke for pointing out that file was already the file name. My other mistake was the brackets around the mxd version number. The final code is as follows.

import arcpy, os
#workspace to search for MXDs
Workspace = r"C:\Testing\ImageMapperReplacement\LRM157"
arcpy.env.workspace = Workspace
#list map documents in folder
mxdList = arcpy.ListFiles("*.mxd")
#set relative path setting for each MXD in list.
for mapdoc in mxdList:
 #set map document to change
 filePath = os.path.join(Workspace, mapdoc)
 mxd = arcpy.mapping.MapDocument(filePath)
 #Get the file name
 basename = mapdoc
 #set relative paths property
 mxd.relativePaths = False
 output = os.path.join(r"C:\Testing\ImageMapperReplacement\LRM157\mxd2", basename)
 #save map doucment change
 mxd.saveACopy (output, '10.0')
answered Sep 24, 2013 at 12:50
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.