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)
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.
mxd = arcpy.mapping.MapDocument("CURRENT") .... mxd.save()
Matt - you mean the mxd object was created from the currently open map document, right?mxd = arcpy.mapping.MapDocument("CURRENT") .... mxd.save()
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...