Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Debugging looped python script (updating picture element link)?

$
0
0

Can anyone help with the following script? It’s goal is to list every mxd in a folder, list picture elements in them and the change the path for a specific element.

Here’s an update version of the script. It goes through and save the document, without error messabge, but doesn’t change the picture element path.

import arcpy
import os

MxdFolderPath = arcpy.GetParameterAsText(0)
if MxdFolderPath == '#' or not MxdFolderPath:
    MxdFolderPath = "//10.13.77.8/MRC_doc/20_Territoires/20-4000_Schema_Amen_Dev/20-4100_Planification/20-4120_Projet_SAD/20-4121_Projet_SAD/Y_Cartographie/A_Planches/Mise_a_jour/Test"
MxdCount = 0

arcpy.env.workspace = MxdFolderPath
arcpy.AddMessage("   MXD PROCESSING")
mxdList = arcpy.ListFiles("*.mxd")
Mxdlen = len(mxdList)
if Mxdlen == 0:
    arcpy.AddMessage("   There are no mxd in: " + str(MxdFolderPath))
else:
    arcpy.AddMessage("   There are " + str(Mxdlen) + " mxd in: " + str(MxdFolderPath))

    for mxd in mxdList:
        mxdPath = os.path.join(MxdFolderPath, mxd)
        MapDoc = arcpy.mapping.MapDocument(mxdPath)
        MapDocElm = arcpy.mapping.ListLayoutElements(MapDoc, "PICTURE_ELEMENT")
        for elm in MapDocElm:
            if elm.name == "LogoMRCL_SloganGrisBlanc.emf":
                elm.sourceImage = r"\10.13.77.8MRC_doc20_Territoires20-4000_Schema_Amen_Dev20-4100_Planification20-4120_Projet_SAD20-4121_Projet_SADY_CartographieA_PlanchesFichiers_de_mise_en_pageVisuelLogoMRCL_SloganGrisBlanc.emf"
            MapDoc.save()
arcpy.AddMessage(" End")

I tried the following script without looping it and it is working.

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for elm in arcpy.mapping.ListLayoutElements(mxd,"PICTURE_ELEMENT"):
    if elm.name == "LogoMRCL_SloganGrisBlanc":
        elm.sourceImage = r"\10.13.77.8MRC_doc20_Territoires20-4000_Schema_Amen_Dev20-4100_Planification20-4120_Projet_SAD20-4121_Projet_SADY_CartographieA_PlanchesFichiers_de_mise_en_pageVisuelLogoMRCL_SloganGrisBlanc.emf"

mxd.save
del mxd

I guess the problem is within the looping part of the script, not with the operation on picture element. Any clue?

EDIT: When the script is ran into PyCharm, this is what comes out:

C:Python27ArcGIS10.3python.exe C:/Users/enclume/PycharmProjects/untitled/updatePictureLinkLoop.py
   MXD PROCESSING
   There are 2 mxd in: //10.13.77.8/MRC_doc/20_Territoires/20-4000_Schema_Amen_Dev/20-4100_Planification/20-4120_Projet_SAD/20-4121_Projet_SAD/Y_Cartographie/A_Planches/Mise_a_jour/Test
[<PictureElement object at 0x23dbcf0[0x23e54f8]>, <PictureElement object at 0xe8a67f0[0xe8ad930]>, <PictureElement object at 0xe8a6810[0xe8ad8e0]>, <PictureElement object at 0xe8a68d0[0xe8adb10]>, <PictureElement object at 0xe8a68f0[0xe8ad908]>, <PictureElement object at 0xe8a6cf0[0xe8adac0]>, <PictureElement object at 0xe8a6d10[0xe8b1d68]>, <PictureElement object at 0xe8a6d30[0xe8b1cf0]>, <PictureElement object at 0xe8a6d50[0xe8b1cc8]>, <PictureElement object at 0xe8a6d70[0xe8b1d90]>, <PictureElement object at 0xe8a6d90[0xe8b1db8]>, <PictureElement object at 0xe8a6db0[0xe8b1de0]>, <PictureElement object at 0xe8a6dd0[0xe8b6228]>, <PictureElement object at 0xe8a6df0[0xe8b6200]>, <PictureElement object at 0xe8a6e10[0xe8b6278]>, <PictureElement object at 0xe8a6e30[0xe8b6250]>, <PictureElement object at 0xe8a6e50[0xe8b6318]>, <PictureElement object at 0xe8a6ef0[0xe8b63b8]>]
[<PictureElement object at 0xe8a6f70[0xe8b69a8]>, <PictureElement object at 0xe8a6f30[0xe8b6980]>, <PictureElement object at 0xe8a6f90[0xe8b6958]>, <PictureElement object at 0xe8a6fb0[0xe8b6930]>, <PictureElement object at 0xe8a6f50[0xe8b6908]>, <PictureElement object at 0xe8a6fd0[0xe8b68e0]>, <PictureElement object at 0xe8a6ff0[0xe8b67f0]>, <PictureElement object at 0x23d7f70[0xe8b67c8]>, <PictureElement object at 0x23d7fb0[0xe8b67a0]>, <PictureElement object at 0xe8c0030[0xe8b6778]>, <PictureElement object at 0xe8c0050[0xe8b6750]>, <PictureElement object at 0xe8c0070[0xe8b6728]>, <PictureElement object at 0xe8c0090[0xe8b6700]>, <PictureElement object at 0xe8c00b0[0xe8b66d8]>, <PictureElement object at 0xe8c00d0[0xe8b6368]>, <PictureElement object at 0xe8c00f0[0xe8b6390]>, <PictureElement object at 0xe8c0110[0xe8b63e0]>, <PictureElement object at 0xe8c0130[0xe8b6408]>, <PictureElement object at 0xe8c01b0[0xe8b6480]>]
Traceback (most recent call last):
  File "C:/Users/enclume/PycharmProjects/untitled/updatePictureLinkLoop.py", line 27, in <module>
    MapDoc.save()
  File "C:Program Files (x86)ArcGISDesktop10.3ArcPyarcpyutils.py", line 182, in fn_
    return fn(*args, **kw)
  File "C:Program Files (x86)ArcGISDesktop10.3ArcPyarcpy_mapping.py", line 850, in save
    return convertArcObjectToPythonObject(self._arc_object.save(*gp_fixargs((), True)))
IOError: MapDocObject: Unable to save.  Check to make sure you have write access to the specified file and that there is enough space on the storage device to hold your document.

Process finished with exit code 1

Viewing all articles
Browse latest Browse all 767

Trending Articles