0

Can't share my script as geoprocesing service. The warning message: 00068 Script Script contains broken project data source: CURRENT Here is the script:

# Import arcpy module
import arcpy
arcpy.env.workspace = "C:\Users\Jack\Desktop\GISBackup\Parcel.gdb"
arcpy.env.overwriteOutput = True

# Script arguments
Input_Feature_Class = arcpy.GetParameterAsText(0)
if  Input_Feature_Class == '#' or not Input_Feature_Class:
    Input_Feature_Class = Parcel_Selected

# Local variables:
SplitLines = arcpy.GetParameterAsText(1)
if  SplitLines == '#' or not SplitLines:
    SplitLines = "ParcelWithLabel"

# Process: Split Line At Vertices
arcpy.SplitLine_management(Input_Feature_Class, SplitLines)

# Process: Delete Identical
arcpy.DeleteIdentical_management(SplitLines, "shape", "", "0")

# Process: Show Labels
mxd = arcpy.mapping.MapDocument("CURRENT") #Map document reference
dataFrame = arcpy.mapping.ListDataFrames(mxd, "*")[0] 
addLayer = arcpy.mapping.Layer(SplitLines)
arcpy.mapping.AddLayer(dataFrame, addLayer)
layer = arcpy.mapping.ListLayers(mxd, "")[0] 
if layer.supports("LABELCLASSES"):
    for lblclass in layer.labelClasses:
          lblclass.showClassLabels = True
          lblclass.expression = '"{}" & round([Shape_Length],2) & "{}"'.format("<FNT name='Arial' size='12'>" , "</FNT>")
layer.showLabels = True
arcpy.RefreshActiveView()
4

You cannot use "CURRENT" in a Geoprocessing Service. The GP Service has no idea what "CURRENT" is as the service isn't an open session of ArcMap. CURRENT is reserved for working with a script inside ArcMap only.

To use arcpy.Mapping, specifically a reference to a map document, you need to provide the full path to the MXD in place of CURRENT.

mxd = arcpy.mapping.MapDocument("c:/myMXDs/project1/thing.mxd")

Also note, the arcpy.RefreshActiveView() isn't going to do anything in a service - again as there is no current "View" to refresh.

You're best stepping back and asking what do you really want the service to do. Once you know that, you'll need to re-design it. As-is it has no output and if you do get it to run, it'll appear nothing has happened.

Additionally, I'd remove these bits, you took your model and exported it to a Python script. These will have little use in a service and are more than likely to break it should the script try to execute this bit of logic.

if  Input_Feature_Class == '#' or not Input_Feature_Class:
    Input_Feature_Class = Parcel_Selected
if  SplitLines == '#' or not SplitLines:
    SplitLines = "ParcelWithLabel"
  • Thank you KHibma, there is no error now. I just want to publish a GP service to show dimensions of a selected polygon – Jack Jul 17 at 1:42
  • @Jack dimensions of a selected polygon? That doesn't sound like anything that requires arcpy.Mapping. But without seeing the big picture, it's hard to say. – KHibma Jul 17 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.