如何将部分路径更改为MXD项目中的图层

问题描述 投票:-1回答:1

如何更改部分路径到MXD项目(ArcMap)中的图层并将更改保存到新项目中?

python arcgis arcpy
1个回答
0
投票
import arcpy, os

def changeMXDFile(fullPath):
    nameWithPath, extension = os.path.splitext(fullPath)
    if extension.lower() == ".mxd":
        mxd = arcpy.mapping.MapDocument(fullPath)
        mxd.findAndReplaceWorkspacePaths(u"\\10.64.68.36\j\folder\", u"\\10.64.68.36\j\f\folder\")
        outputFile = os.path.join(outputFolder, os.path.basename(nameWithPath) + ".mxd")
        mxd.saveACopy(outputFile, "10.3")
        arcpy.AddMessage("file " + os.path.basename(nameWithPath) + ".mxd is change")
        del mxd

if __name__ == '__main__':
    inputFolder = arcpy.GetParameterAsText(0) #folder with input files mxd 
    outputFolder = arcpy.GetParameterAsText(1) #folder with output files mxd
    for fileName in os.listdir(inputFolder):
        fullPath = os.path.join(inputFolder, fileName)
        if os.path.isfile(fullPath): changeMXDFile(fullPath)
© www.soinside.com 2019 - 2024. All rights reserved.