0

I am trying to batch export several MXD files into corresponding separate GIF files. I am using the script below but am not having much luck and am getting an error: 'Invalid MXD filename'

import arcpy, os
Workspace = "J:\\IrrigatedLands"
arcpy.env.workspace = Workspace
mxdList = arcpy.ListFiles("*.mxd")

for mxd in mxdList:
    gifname = "J:\\IrrigatedLands_temp.gif"
    arcpy.mapping.ExportToGIF(mxd, gifname)
3

It appears you need to use arcpy.mapping.MapDocument

import arcpy, os
Workspace = "J:\\IrrigatedLands"
arcpy.env.workspace = Workspace
mxdList = arcpy.ListFiles("*.mxd")
i = 0
for mxd in mxdList:
    i += 1
    outmxd = arcpy.mapping.MapDocument(Workspace + "\\" + mxd)
    gifname = Workspace + "\\IrrigatedLands_temp_{}.gif".format(i)
    arcpy.mapping.ExportToGIF(outmxd, gifname)

I've also added a number to each output file otherwise it would have overwritten the same gif for each mxd, so output would be something like IrrigatedLands_temp_1.gif

  • Thank you for the help! The code seems to work fairly well except that the 'temp.gif' files only have the Title and Legends but no map images. Below is the error that returned from the script. – brgionta Jan 27 '16 at 0:06
  • Traceback (most recent call last): File "F:/IrrigatedLands/test1", line 10, in <module> arcpy.mapping.ExportToGIF(outmxd,gifname) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line 936, in ExportToGIF layout.exportToGIF(*args) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) – brgionta Jan 27 '16 at 0:13
  • File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 557, in exportToGIF return self._arc_object.exportToGIF(*args) AttributeError: 'NoneType' object has no attribute 'exportToGIF' – brgionta Jan 27 '16 at 0:13
  • It may be looking for a Data Frame to export, as per ArcGIS Help - ExportToGIF. If you have a Page Layout you can use "PAGE_LAYOUT" in arcpy.mapping.ExportToGIF(outmxd, gifname, "PAGE_LAYOUT") otherwise you may need to specify a Data Frame name. – Midavalo Jan 27 '16 at 0:21
  • Seems to be working now. Cheers! – brgionta Jan 27 '16 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.