Select to view content in your preferred language

saving/disk space error

2923
5
12-11-2012 06:00 AM
ChristopherBride
Deactivated User

This error has been plaguing my final project for weeks and I really need a solution to it. I am using the code below. It only works when the map is not open. When it is open, I get the following error: 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. Which is ridiculous because I am using my personal computer and I have a huge hard drive.

arcpy.workspace = r"C:\Users\me\Documents\School\GEP662\FinalMaterial\MapData"
inFC = "HudsonRiverSamplingHyperlinks.shp"
arcpy.MakeFeatureLayer_management(inFC, "HudsonRiverSamplingHyperlinks_layer")
arcpy.ApplySymbologyFromLayer_management("HudsonRiverSamplingHyperlinks_layer", 
   "RKSymbologyLayer.lyr")
lyrLayer = arcpy.mapping.Layer("HudsonRiverSamplingHyperlinks_layer")
arcpy.mapping.AddLayer(df, lyrLayer, "AUTO_ARRANGE")
   
mxd.save()

del mxd

print "completed successfully"

But like I said, when the map is closed, it works fine. This is a problem because i need to create a tool in C# that utilizes the script when the map is open. Should I use saveACopy? Seems like I used that while troubleshooting and it came back with the same error.

(Curtis Price formatted the code, see Posting Code blocks in the new GeoNet​)

Tags (2)
0 Kudos
5 Replies
MathewCoyle
Honored Contributor
You cannot use mxd.save() while the target map document is open unless you call this from within the mxd using the "current" parameter for the path.
0 Kudos
curtvprice
MVP Alum
You cannot use mxd.save() while the target map document is open unless you call this from within the mxd using the "current" parameter for the path.


Matt - you mean the mxd object was created from the currently open map document, right?

mxd = arcpy.mapping.MapDocument("CURRENT")
....
mxd.save()
0 Kudos
MathewCoyle
Honored Contributor
Matt - you mean the mxd object was created from the currently open map document, right?

mxd = arcpy.mapping.MapDocument("CURRENT")
....
mxd.save()


Yes exactly Curtis, sorry if it wasn't clear. I had meant to attach the code you did.
0 Kudos
ChristopherBride
Deactivated User
Thanks for the response...so do I only have to put in "CURRENT" within the parenthesis or do I need to add in the file path as well? I'm trying it with just "CURRENT" and it's not going through...
0 Kudos
MathewCoyle
Honored Contributor
Thanks for the response...so do I only have to put in "CURRENT" within the parenthesis or do I need to add in the file path as well? I'm trying it with just "CURRENT" and it's not going through...


You can look at some of the examples in the help to get an idea of how to use the arcpy.mapping module.
0 Kudos