Select to view content in your preferred language

arcpy.mapping.MapDocument bug

3978
11
06-18-2012 03:45 AM
CyrilleMedard_de_Chardon
New Contributor III
The MapDocument Syntax clearly states that the first input is:
"A string that includes the full path and file name of an existing map document (.mxd) or a string that contains the keyword CURRENT"

The bug is that arcpy.mapping.MapDocument() happily accepts a partial/relative path yet only provides limited functionality. The arcpy.mapping.MapDocument object will fail depending on the method called. The errors messages of the methods do not refer to the cause.

A simple example
import arcpy  arcpy.env.workspace = "c:/arcgis/"  # Using a relative path mxd = arcpy.mapping.MapDocument('maps/template.mxd')  #works mxd.save()  #fails -> "AttributeError: 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." mxd.saveACopy('template_copy.mxd')


When providing a full path to the MapDocument class no error is encountered when calling the saveACopy() method.

The existing saveACopy() error is red herring. Upon receiving a relative path the MapDocument class should return an error.

Regards,
Cyrille
Tags (2)
0 Kudos
11 Replies
JeffBarrette
Esri Regular Contributor
I don't understand, is is really a bug if it is documented to use "full paths" or "CURRENT"?

I use relative paths all the time but I'm actually providing a full path to the MapDocument function:

import arcpy, os, sys
relPath = os.path.dirname(sys.argv[0])
mxd = arcpy.mapping.MapDocument(relPath + r"\project.mxd")


Jeff
0 Kudos
CyrilleMedard_de_Chardon
New Contributor III
Hi Jeff,

When used correctly there is no problem (full path as in your example).
The bug is that there exists limited functionality when using relative paths. An error should be thrown by arcpy.mapping.MapDocument immediately upon receiving a relative path and not later due to operations using the map document object constructed using a relative path.

Regards,
Cyrille
0 Kudos