1

I am trying to take the guts of this code (Batch convert ArcGIS 9x files to 10) and build it into a tool that we can more flexibly use and share around our organization. I think I'm almost there but when I run the tool as a script in Arc, nothing happens. Thoughts? Thanks for your help. I'm fairly new to Python but am pretty good on where the guts of it all is.

mxdinloc is set to a folder

mxdoutvers is set to a string - value list where the list choices are (10.1, 10.0, 9.3, 9.2) - no quotes

EDIT: I ran through, got it working and wanted to share the final bit that I brought into my Script Toolbox:

#import modules
import arcpy
import os
import glob

#set parameters for inputs
mxdinloc = arcpy.GetParameterAsText(0)
mxdoutvers = arcpy.GetParameterAsText(1)

#set the values for input versions of ArcMap
if mxdoutvers == "10.1":
    version = "10.1"
    suffix = "_(10.1)"
elif mxdoutvers == "10.0":
    version = "10.0"
    suffix = "_(10.0)"
elif mxdoutvers == "9.3":
    version = "9.3"
    suffix = "_(9.3)"
elif mxdoutvers == "9.2":
    version = "9.2"
    suffix = "_(9.2)"

for pathname, directories, filenames in os.walk(mxdinloc):
    for filename in filenames:
        if filename.lower().endswith(".mxd"):
            print "\nUpdating: " + filename
            mxd = arcpy.mapping.MapDocument(mxdinloc + "\\" + filename)
            filename, ext = os.path.splitext(mxdinloc + "\\" + filename)
            print filename
            if mxd.dateSaved:
                print mxd.dateSaved
                mxd.saveACopy(filename + suffix + ext, mxdoutvers)
                currentMxd = filename + suffix + ext
                mapDoc = arcpy.mapping.MapDocument(currentMxd)
                print "Updated: " + filename + "\n"
        else:
            print "\n" + filename + " is not a MXD and was not updated. \n"
4
  • 1
    Why are you setting mxdinloc = os.getcwd()? If anything, you want to use os.chdir(mxdinloc) to set the current directory. I would hardcode the parameters in and run it outside ArcMap with print statements to see what's wrong.
    – ianbroad
    Commented Aug 20, 2014 at 22:24
  • You can use sys.argv[1] and [2] instead of arcpy.GetParameterAsText(0) and (1) on the command line. Ian is right, you are overwriting your location to the os.getcwd() which will not be your input directory. If you use arcpy.AddMessage(os.getcwd) it will report where you currently are (the current working directory) which is likely to be either your temp directory or home directory in your user profile. If you are using os.getcwd on the command line then change directory (CD) to the location where you want to start, if you are running in python window change print to arcpy.AddMessage. Commented Aug 20, 2014 at 22:31
  • took your advice & hard coded the params, got it working. thanks!
    – tay bro
    Commented Aug 21, 2014 at 19:25
  • @taybro Glad to hear!
    – ianbroad
    Commented Aug 21, 2014 at 21:23

0

Browse other questions tagged or ask your own question.