Skip to main content
corrected spelling
Source Link
nmtoken
  • 13.6k
  • 5
  • 38
  • 89

I posted How to save just some mxds through 'if' in python? yesterday, and now iI want to do a change in the script.

I changed the script, to run over subfolderssub-folders. It It goes nice, but when it jumps another folder level, for the second time, iI got an error:

Traceback (most recent call last):
  File "D:\teste\change_jpg_layout_subfolder.py", line 18, in <module>
    mxds = arcpy.mapping.MapDocument(MXDpath)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__
    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.

There is nothing wrong with the foldernames and mxdnames. No special characters, no spaces, nothing. It just dontdoesn't go further. This

This is the code now:

import arcpy, os, glob 


source = os.curdir
mxdList = []
   

for dirpath, subdirs, files in os.walk(source):
  for x in files:
    if x.endswith(".mxd"):
      mxdList.append(os.path.join(dirpath, x))

print mxdList

for mxd in mxdList:
    MXDpath = mxd
    mxds = arcpy.mapping.MapDocument(MXDpath)
    for elm in arcpy.mapping.ListLayoutElements(mxds, "PICTURE_ELEMENT"):
        if elm.name == "logo":
            elm.sourceImage = r"C:\logo\newlogo.jpg"
            print MXDpath
            mxds.save()
        del mxds

Can you help me please, again? I also wanted to put the "mxds.save()" under a "try" conditional, that if for a reason the script coudntcouldn't save it, the script goes on... But i didntI don't know how to do it.

thisThis is my folder structure  :

folder structure

I posted How to save just some mxds through 'if' in python? yesterday, and now i want to do a change in the script.

I changed the script, to run over subfolders. It goes nice, but when it jumps another folder level, for the second time, i got an error:

Traceback (most recent call last):
  File "D:\teste\change_jpg_layout_subfolder.py", line 18, in <module>
    mxds = arcpy.mapping.MapDocument(MXDpath)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__
    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.

There is nothing wrong with the foldernames and mxdnames. No special characters, no spaces, nothing. It just dont go further. This is the code now:

import arcpy, os, glob

source = os.curdir
mxdList = []
 

for dirpath, subdirs, files in os.walk(source):
  for x in files:
    if x.endswith(".mxd"):
      mxdList.append(os.path.join(dirpath, x))

print mxdList

for mxd in mxdList:
    MXDpath = mxd
    mxds = arcpy.mapping.MapDocument(MXDpath)
    for elm in arcpy.mapping.ListLayoutElements(mxds, "PICTURE_ELEMENT"):
        if elm.name == "logo":
            elm.sourceImage = r"C:\logo\newlogo.jpg"
            print MXDpath
            mxds.save()
        del mxds

Can you help me please, again? I also wanted to put the "mxds.save()" under a "try" conditional, that if for a reason the script coudnt save it, the script goes on.. But i didnt know how to do it.

this is my folder structure  folder structure

I posted How to save just some mxds through 'if' in python? yesterday, and now I want to do a change in the script.

I changed the script, to run over sub-folders. It goes nice, but when it jumps another folder level, for the second time, I got an error:

Traceback (most recent call last):
  File "D:\teste\change_jpg_layout_subfolder.py", line 18, in <module>
    mxds = arcpy.mapping.MapDocument(MXDpath)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__
    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.

There is nothing wrong with the foldernames and mxdnames. No special characters, no spaces, nothing. It just doesn't go further.

This is the code now:

import arcpy, os, glob 


source = os.curdir
mxdList = []  

for dirpath, subdirs, files in os.walk(source):
  for x in files:
    if x.endswith(".mxd"):
      mxdList.append(os.path.join(dirpath, x))

print mxdList

for mxd in mxdList:
    MXDpath = mxd
    mxds = arcpy.mapping.MapDocument(MXDpath)
    for elm in arcpy.mapping.ListLayoutElements(mxds, "PICTURE_ELEMENT"):
        if elm.name == "logo":
            elm.sourceImage = r"C:\logo\newlogo.jpg"
            print MXDpath
            mxds.save()
        del mxds

Can you help me please, again? I also wanted to put the "mxds.save()" under a "try" conditional, that if for a reason the script couldn't save it, the script goes on... But I don't know how to do it.

This is my folder structure:

folder structure

deleted 11 characters in body
Source Link
raphael
  • 171
  • 1
  • 9

I posted How to save just some mxds through 'if' in python? yesterday, and now i want to do a change in the script.

I changed the script, to run over subfolders. It goes nice, but when it jumps another folder level, for the second time, i got an error:

Traceback (most recent call last):
  File "D:\teste\change_jpg_layout_subfolder.py", line 18, in <module>
    mxds = arcpy.mapping.MapDocument(MXDpath)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__
    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.

There is nothing wrong with the foldernames and mxdnames. No special characters, no spaces, nothing. It just dont go further. This is the code now:

import arcpy, os, glob

source = os.curdir
mxdList = []


for dirpath, subdirs, files in os.walk(source):
  for x in files:
    if x.endswith(".mxd"):
      mxdList.append(os.path.join(dirpath, x))

print mxdList

for mxd in mxdList:
    MXDpath = mxd
    mxds = arcpy.mapping.MapDocument(MXDpath)
    for elm in arcpy.mapping.ListLayoutElements(mxds, "PICTURE_ELEMENT"):
        if elm.name == "logo":
            elm.sourceImage = r"C:\logo\newlogo.jpg"
            print MXDpath
            mxds.save()
        del mxds

Can you help me please, again? I also wanted to put the "mxds.save()" under a "try" conditional, that if for a reason the script coudnt save it, the script goes on.. But i didnt know how to do it.

this is my folder structure folder structure

I posted How to save just some mxds through 'if' in python? yesterday, and now i want to do a change in the script.

I changed the script, to run over subfolders. It goes nice, but when it jumps another folder level, for the second time, i got an error:

Traceback (most recent call last):
  File "D:\teste\change_jpg_layout_subfolder.py", line 18, in <module>
    mxds = arcpy.mapping.MapDocument(MXDpath)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__
    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.

There is nothing wrong with the foldernames and mxdnames. No special characters, no spaces, nothing. It just dont go further. This is the code now:

import arcpy, os, glob

source = os.curdir
mxdList = []


for dirpath, subdirs, files in os.walk(source):
  for x in files:
    if x.endswith(".mxd"):
      mxdList.append(os.path.join(dirpath, x))

print mxdList

for mxd in mxdList:
    MXDpath = mxd
    mxds = arcpy.mapping.MapDocument(MXDpath)
    for elm in arcpy.mapping.ListLayoutElements(mxds, "PICTURE_ELEMENT"):
        if elm.name == "logo":
            elm.sourceImage = r"C:\logo\newlogo.jpg"
            print MXDpath
            mxds.save()
        del mxds

Can you help me please, again? I also wanted to put the "mxds.save()" under a "try" conditional, that if for a reason the script coudnt save it, the script goes on.. But i didnt know how to do it.

I posted How to save just some mxds through 'if' in python? yesterday, and now i want to do a change in the script.

I changed the script, to run over subfolders. It goes nice, but when it jumps another folder level, for the second time, i got an error:

Traceback (most recent call last):
  File "D:\teste\change_jpg_layout_subfolder.py", line 18, in <module>
    mxds = arcpy.mapping.MapDocument(MXDpath)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__
    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.

There is nothing wrong with the foldernames and mxdnames. No special characters, no spaces, nothing. It just dont go further. This is the code now:

import arcpy, os, glob

source = os.curdir
mxdList = []


for dirpath, subdirs, files in os.walk(source):
  for x in files:
    if x.endswith(".mxd"):
      mxdList.append(os.path.join(dirpath, x))

print mxdList

for mxd in mxdList:
    MXDpath = mxd
    mxds = arcpy.mapping.MapDocument(MXDpath)
    for elm in arcpy.mapping.ListLayoutElements(mxds, "PICTURE_ELEMENT"):
        if elm.name == "logo":
            elm.sourceImage = r"C:\logo\newlogo.jpg"
            print MXDpath
            mxds.save()
        del mxds

Can you help me please, again? I also wanted to put the "mxds.save()" under a "try" conditional, that if for a reason the script coudnt save it, the script goes on.. But i didnt know how to do it.

this is my folder structure folder structure

edited tags; added 1 character in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

iI posted a questionHow to save just some mxds through 'if' in python? yesterday, and now i want to do a change in the script.

last question link

I changed the script, to run over subfolders. It goes nice, but when it jumps another folder level, for the second time, i got an error:

Traceback (most recent call last):
  File "D:\teste\change_jpg_layout_subfolder.py", line 18, in <module>
    mxds = arcpy.mapping.MapDocument(MXDpath)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__
    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.

There is nothing wrong with the foldernames and mxdnames. No special characters, no spaces, nothing. It just dont go further. This is the code now:

import arcpy, os, glob

source = os.curdir
mxdList = []


for dirpath, subdirs, files in os.walk(source):
  for x in files:
    if x.endswith(".mxd"):
      mxdList.append(os.path.join(dirpath, x))

print mxdList

for mxd in mxdList:
    MXDpath = mxd
    mxds = arcpy.mapping.MapDocument(MXDpath)
    for elm in arcpy.mapping.ListLayoutElements(mxds, "PICTURE_ELEMENT"):
        if elm.name == "logo":
            elm.sourceImage = r"C:\logo\newlogo.jpg"
            print MXDpath
            mxds.save()
        del mxds

Can you help me please, again? I also wanted to put the "mxds.save()" under a "try" conditional, that if for a reason the script coudnt save it, the script goes on.. But i didnt know how to do it.

i posted a question yesterday, and now i want to do a change in the script.

last question link

I changed the script, to run over subfolders. It goes nice, but when it jumps another folder level, for the second time, i got an error:

Traceback (most recent call last):
  File "D:\teste\change_jpg_layout_subfolder.py", line 18, in <module>
    mxds = arcpy.mapping.MapDocument(MXDpath)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__
    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.

There is nothing wrong with the foldernames and mxdnames. No special characters, no spaces, nothing. It just dont go further. This is the code now:

import arcpy, os, glob

source = os.curdir
mxdList = []


for dirpath, subdirs, files in os.walk(source):
  for x in files:
    if x.endswith(".mxd"):
      mxdList.append(os.path.join(dirpath, x))

print mxdList

for mxd in mxdList:
    MXDpath = mxd
    mxds = arcpy.mapping.MapDocument(MXDpath)
    for elm in arcpy.mapping.ListLayoutElements(mxds, "PICTURE_ELEMENT"):
        if elm.name == "logo":
            elm.sourceImage = r"C:\logo\newlogo.jpg"
            print MXDpath
            mxds.save()
        del mxds

Can you help me please, again? I also wanted to put the "mxds.save()" under a "try" conditional, that if for a reason the script coudnt save it, the script goes on.. But i didnt know how to do it.

I posted How to save just some mxds through 'if' in python? yesterday, and now i want to do a change in the script.

I changed the script, to run over subfolders. It goes nice, but when it jumps another folder level, for the second time, i got an error:

Traceback (most recent call last):
  File "D:\teste\change_jpg_layout_subfolder.py", line 18, in <module>
    mxds = arcpy.mapping.MapDocument(MXDpath)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__
    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.

There is nothing wrong with the foldernames and mxdnames. No special characters, no spaces, nothing. It just dont go further. This is the code now:

import arcpy, os, glob

source = os.curdir
mxdList = []


for dirpath, subdirs, files in os.walk(source):
  for x in files:
    if x.endswith(".mxd"):
      mxdList.append(os.path.join(dirpath, x))

print mxdList

for mxd in mxdList:
    MXDpath = mxd
    mxds = arcpy.mapping.MapDocument(MXDpath)
    for elm in arcpy.mapping.ListLayoutElements(mxds, "PICTURE_ELEMENT"):
        if elm.name == "logo":
            elm.sourceImage = r"C:\logo\newlogo.jpg"
            print MXDpath
            mxds.save()
        del mxds

Can you help me please, again? I also wanted to put the "mxds.save()" under a "try" conditional, that if for a reason the script coudnt save it, the script goes on.. But i didnt know how to do it.

Source Link
raphael
  • 171
  • 1
  • 9
Loading