arcpy.mapping.MapDocument(“CURRENT”)

27733
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
JeffWard
Occasional Contributor III

The "CURRENT" constant is for use while using ArcMap.  It isn't going to mean anything to your geoprocessing service.  You need to pass the path to an mxd document.

Jeff Ward
Summit County, Utah
LaszloCsunderlik
New Contributor II

But if i change the "CURRENT" part to the path, after the script doesn't load the result. Or should I change something more in the script?

0 Kudos
JeffWard
Occasional Contributor III

Are you enclosing the path in quotes?  I believe it wants the path as a string and passing paths in python is tricky.  But something like r'C:\folder\filename.mxd' will work.  Or 'C:\\folder\\filename.mxd' or 'C:/folder/filename.mxd'

Jeff Ward
Summit County, Utah
0 Kudos
LaszloCsunderlik
New Contributor II

Yes I am encosing the path in quotes. I tried the path as a string, but none of your suggestion worked. Any idea? I didn't know that passing paths in python is so tricky. Or there is another problem in the script?

0 Kudos
JeffWard
Occasional Contributor III

What error are you getting now?  Can you post your revised code using this method in a reply so it doesn't need to be downloaded?

Jeff Ward
Summit County, Utah
0 Kudos
JeffWard
Occasional Contributor III

And you might want to unmark this question as answered if you want others to chime in.

Jeff Ward
Summit County, Utah
0 Kudos
LaszloCsunderlik
New Contributor II

First of all thanks for the usefull notes.

Unfortunately there is no error message, the script runs perfectly, but it doesn't show the result shp file. I checked  the path, and always there is the new shp, but the script doesn't add it to the TOC. I can't use the above mentioned method....

0 Kudos
JeffWard
Occasional Contributor III

Copy your code, paste it into a reply here on GeoNet, then click on "Use advanced editor" in the upper right hand side of your reply. Select the text of your code and click on >> above to the right of the smilies, hover over Syntax Highlighting and scroll down to python.  That way your code is formatted for display and allows a responder to read it and troubleshoot it without having to download.

It sounds like you aren't saving the mxd?

mxd.save()

Jeff Ward
Summit County, Utah
0 Kudos
LaszloCsunderlik
New Contributor II

I saved the mxd. It is in the folder: C:\\temperature\\result\\mean.mxd

Here we go:

import os, sys
import shutil
import arcpy
from arcpy import env
arcpy.CheckOutExtension("spatial")
from arcpy.sa import *
arcpy.env.overwriteOutput = True
start_date = arcpy.GetParameterAsText(0)
end_date = arcpy.GetParameterAsText(1) 
env.workspace = "c:/temperature/input"
rasters = arcpy.ListRasters("*","GRID")
for raster in rasters:
    if int(raster) >= int(start_date) and int(raster) <= int(end_date):
        arcpy.CopyRaster_management((raster), "c:/temperature/query/" + (raster) + ".tif", "", "", "", "NONE", "NONE", "", "NONE", "NONE")
env.workspace = "c:/temperature/query"
eredmeny = "c:/temperature/result/atlag.tif"
rasterses = arcpy.ListRasters("*","TIF")
result = arcpy.gp.CellStatistics_sa((rasterses), eredmeny, "MEAN", "DATA")
env.workspace = "c:/temperature/query"
rasters = arcpy.ListRasters("*","TIF")
for oldraster in rasterses:
  arcpy.Delete_management(oldraster)
env.workspace = "c:/temperature/result"
outInt = Int("atlag.tif")
outInt.save("c:/temperature/result/atlagint.tif")
env.workspace = "c:/temperature/result"
arcpy.RasterToPolygon_conversion("c:/temperature/result/atlagint.tif", "c:/temperature/result/atlagint.shp", "SIMPLIFY", "VALUE")


# get the map document
mxd = arcpy.mapping.MapDocument (r'C:\\temperature\\result\\mean.mxd')
# get the data frame
df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
# create a new layer
newlayer = arcpy.mapping.Layer("c:/temperature/result/atlagint.shp")
# add the layer to the map at the top of the TOC in data frame 0
arcpy.mapping.AddLayer(df, newlayer, "TOP")
sourceLayer = "c:/temperature/result/symbology.lyr"
layerSymb = arcpy.mapping.Layer(sourceLayer) 
updateLayer = arcpy.mapping.ListLayers(mxd, "atlagint", df)[0] 
arcpy.mapping.UpdateLayer(df, updateLayer, layerSymb, "TRUE") 
arcpy.RefreshTOC()
arcpy.RefreshActiveView()


lyrFile = arcpy.mapping.Layer("c:/temperature/result/symbology.lyr")
for lyr in arcpy.mapping.ListLayers(lyrFile, "c:/temperature/result/atlagint.shp"):
    lyr.showLabels = True
    lyr.saveACopy("c:/temperature/result/symbologyLabels.lyr")
exit()
0 Kudos