ryankelley001

arcpy convert MXT map templates to MXDs

Discussion created by ryankelley001 on Jan 11, 2011
We'd like to have a way for a user to run a tool that takes mxt's in a specified folder and changes them to output as mxd's in a specified folder.  I wrote a simple script, that works, but it doesn't seem legitimate... I am basically splitting the filename on the "." and adding "mxd" rather than "mxt". Then I use the mxd.save() command on all mxd's in the output directory.  MXDs open up fine and don't show any signs of issues... is there a better way to go about this?

    
    mxtPath = arcpy.GetParameterAsText(0)
    outPath = arcpy.GetParameterAsText(1)

    for filename in os.listdir(mxtPath):
        fullpath = os.path.join(mxtPath, filename)
        if os.path.isfile(fullpath):
            basename, extension = filename.split(".")
            if extension == "mxt":
                shutil.copyfile(mxtPath + "\\" + filename, outPath + "\\" + basename + ".mxd")
                del filename, fullpath, extension, basename
                
    for filename in os.listdir(outPath):
        fullpath = os.path.join(outPath, filename)
        arcpy.AddMessage(filename)
        if os.path.isfile(fullpath):
            basename, extension = filename.split(".")
            if extension == "mxd":
                mxd = MAP.MapDocument(outPath + "\\" + filename)
                mxd.save()

Outcomes