arcpy.mapping.MapDocument(“CURRENT”)

27744
21
05-21-2015 10:41 AM
LaszloCsunderlik
New Contributor II

Hi Guys!

I am writing a web application for my thesis in ArcPy and I would like to share my script code with the Flex but I can't share my script as geoprocesing service. The warning message: 00068 Script Script contains broken project data source: CURRENT Here is the script, where the "CURRENT" mapping module is. See attached!!

It would be very helpful if someone could find a solution for this. This script is working prefectly in desktop, I just can't publish because this error message.

Tags (1)
21 Replies
NeillJobe
Occasional Contributor II

Hey guys, would you mind moving the original post to another Place on GEONet? None of this is related to Admin Tools for ArcGIS Online.

Thanks,

Neill

0 Kudos
CarlSunderman
Occasional Contributor

try:

FC = "c:/temperature/result/atlagint.shp"
  
arcpy.MakeFeatureLayer_management(FC, newlayer)
  
arcpy.mapping.AddLayer(df, newlayer, "TOP")
0 Kudos
LaszloCsunderlik
New Contributor II

I tried with this too, but it isn't working. I have no idea what can be the soluton for this, because it is just a simple "add shp to the TOC" and still it is the hardest part...

0 Kudos
LukeWebb
Occasional Contributor III

To save the changes within the mxd, you need a line of code within the script, you will also have to reopen the mxd after the script is run!:

  1. arcpy.RefreshTOC() 
  2. arcp.RefreshActiveView() 
  3. mxd.save()

Hopefully this helps.

0 Kudos
LaszloCsunderlik
New Contributor II

Still doesn't working the script. I mean doesn't add the shp to the TOC.

After the

mxd.save()

I got this error message:

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.

And the weirdest part is if I manually drag and drop the result atlagint.shp to the TOC, after the second run automatically add the script the new atlagint.shp to the TOC.

Any idea?

0 Kudos
LukeWebb
Occasional Contributor III

Are you trying to save the mxd via web service or an external python editor or similar?,   whilst you also have the mxd open in desktop GIS? 

0 Kudos
LaszloCsunderlik
New Contributor II

I did the python script by an external python editor (notead++), and yes i have the mxd open in desktop GIS.

0 Kudos
LukeWebb
Occasional Contributor III

The reason I asked is because that error is usually caused by having the same MXD  file being read at the same time by 2x processes, for example if you were running the script using one ArcMAP window, and you had the same mxd open in a different ArcMAP window, or computer.

Try closing everything except one ArcMAP window and running the script, does the error still occur?

From your reply I guess you are using ArcMAP to run the script, not notepad ++.

0 Kudos
LaszloCsunderlik
New Contributor II

If i delete the

mxd.save()

part, the script runs without error message, but doens't add the final shp to the map. I closed everything except the ArcMAP window. If I left the mxd.save() in the script i have the above mentioned error message, btw the script creates the atlagint.shp.

And the weirdest part:

After the first run the script doens't add the atlagint.shp to the TOC.

If I add it manually (drag and drop) after the 2nd run the script add automatically the new atlagint.shp to the map...

0 Kudos
LukeWebb
Occasional Contributor III

the weird part is because when you add a shapefile to the map, it doesnt add a shapefile to the map, it adds a "link to a shapefile" to the map.

As you have added the link to the shapefile into the map already, when you run the script, it overwrites the shapefile so it updates inside the map. The script itself hasn't changed anything to do with this, except update the shapefile itself, which is already in the map as you added it manually.

Without the line mxd.save(), any changes that you make to the mxd will not be saved, however the shapefiles in the map which the script has managed to edit, will be updated.

When you say you closed everything except one Arc window, is that the window you then ran the script in?

Try opening the Python window (Geoprocessing Menu --> Python)

Then type:

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

>>> mxd.save()

Does this crash also?

0 Kudos