Hello:I've got a script that works consistently in Catalog/Desktop but it fails unexpectedly once published as Geoprocessing Service. It's driving me nuts and I hope I'm missing something obvious.Also: What are good ways to troubleshoot it? Is there a way I can force Server to keep the resulting data so I can look at it? Can I get Flex to output messages at my will from the script? Ie. the way I can arcpy.addMessage("var X broke!")The code below breaks at the last line I have provided with the error: "C:\arcgisserver\directories\arcgissystem\arcgisinput\rq10.GPServer\extracted\v101\published_data\rq.py", line 120, in <module>
boxWidth = boxXMax-boxXMin
NameError: name 'boxXMax' is not defined
Failed to execute (rq).
I assume the error is because boxXMax is never being made, which I assume because row3 is null because there are no entries for the SearchCursor. But why is that data coming back empty? How could I test or investigate this?
# Esri start of added imports
import sys, os, arcpy
# Esri end of added imports
# Esri start of added variables
g_ESRI_variable_1 = u'%scratchGDB%\\inputPoint'
g_ESRI_variable_2 = u'%scratchGDB%\\waterbodyPoly'
g_ESRI_variable_3 = u'%scratchGDB%\\waterbodyBuffer'
g_ESRI_variable_4 = u'%scratchGDB%\\waterbodyBound'
g_ESRI_variable_5 = u'angle'
g_ESRI_variable_6 = u'%scratchGDB%\\waterbodyBuffLine'
g_ESRI_variable_7 = os.path.join(arcpy.env.packageWorkspace,u'scratch.gdb\\pathLines')
g_ESRI_variable_8 = u'%scratchGDB%\\intersectPoints'
g_ESRI_variable_9 = u'%scratchGDB%\\intersectSinglePts'
g_ESRI_variable_10 = u'%scratchGDB%\\waypoints'
# Esri end of added variables
#Imports
import arcpy
from arcpy import env
from math import radians, tan, cos
env.overwriteOutput = True
env.workspace = arcpy.env.packageWorkspace
env.scratchWorkspace = "c:\published_data\scratch.gdb"
### INPUTS / OUTPUTS ###
wBody = arcpy.GetParameterAsText(0)
inPoint = arcpy.GetParameterAsText(1)
transSpacing = float(arcpy.GetParameterAsText(2))
shorelineBuffer = float(arcpy.GetParameterAsText(3))
outTransect = arcpy.GetParameterAsText(4)
rotation_method = arcpy.GetParameterAsText(5)
#Project Data
sr = arcpy.SpatialReference()
sr.factoryCode = 32617
sr.create()
#wbpoly waterbodypoly
#inpoint inputpoint
inputPoint = arcpy.Project_management(inPoint,g_ESRI_variable_1,sr)
waterbodyPoly = arcpy.Project_management(wBody,g_ESRI_variable_2,sr)
### VARIABLES ###
kfPerimeter = shorelineBuffer - (transSpacing / 2)
sRef = arcpy.Describe(waterbodyPoly).spatialReference
# Get start point from geometry
startPoint = arcpy.Point()
descInPoint = arcpy.Describe(inputPoint)
sfName = descInPoint.ShapeFieldName
rows = arcpy.SearchCursor(inputPoint)
for row in rows:
feat = row.getValue(sfName)
pnt = feat.getPart()
startPoint.X = pnt.X
startPoint.Y = pnt.Y
startPoint.ID = 0
# New empty polyline FC.
arcpy.CreateFeatureclass_management(env.scratchGDB,"pathLines", "POLYLINE", spatial_reference = sRef)
# Buffer Waterbody
arcpy.Buffer_analysis(waterbodyPoly,g_ESRI_variable_3,0.0 - shorelineBuffer)
# Get Bounding Box
arcpy.MinimumBoundingGeometry_management(g_ESRI_variable_3,g_ESRI_variable_4,"RECTANGLE_BY_WIDTH")
# Add "angle" Field
arcpy.AddField_management(g_ESRI_variable_4,"angle","DOUBLE")
# Calculate Angle
arcpy.CalculatePolygonMainAngle_cartography(g_ESRI_variable_4, g_ESRI_variable_5, rotation_method)
# Get Angle as var
sCur = arcpy.SearchCursor(g_ESRI_variable_4)
for row2 in sCur:
angle = row2.angle
# Waterbody to polyline
arcpy.PolygonToLine_management(g_ESRI_variable_3, g_ESRI_variable_6)
# Build Transect Lines based on primary angles
# Get bounding box extents
bBoxCur = arcpy.SearchCursor(g_ESRI_variable_4)
for row3 in bBoxCur:
geom = row3.shape
ext = geom.extent
boxXMin = ext.XMin
boxXMax = ext.XMax
boxYMin = ext.YMin
boxYMax = ext.YMax
boxWidth = boxXMax-boxXMin