I have created an python toolbox to allow users to link a selected polygon to a image file. The user starts a versioned editing session, creates the polygon, browses to the image file and executes the script. An arcpy.da.UpdateCursor adds the file name and several paths to our web server to the fields in the selected polygon. The error that I get when I try to save the edits is :There was an error executing the queryThe requested operation is invalid for a closed state[GIS.CSIDistrictDrawing][STATE_ID=9351]
Any ideas of what is wrong?
import arcpy, sys, os class Toolbox(object): def __init__(self): self.label = u'Polygon Linker' self.alias = '' self.tools = [PolygonLinker] class PolygonLinker(object): def __init__(self): self.label = u'Polygon Linker' self.description = u'' self.canRunInBackground = False def getParameterInfo(self): # Reference_Polygon_Feature_Class param_1 = arcpy.Parameter() param_1.name = u'Reference_Polygon_Feature_Class' param_1.displayName = u'Reference Polygon Feature Class' param_1.parameterType = 'Required' param_1.direction = 'Input' param_1.datatype = u'GPLayer' # File_to_link_to param_2 = arcpy.Parameter() param_2.name = u'File_to_link_to' param_2.displayName = u'File to link to' param_2.parameterType = 'Required' param_2.direction = 'Input' param_2.datatype = 'DEFile' param_2.filter.list = ['tif', 'tiff', 'pdf'] # Comments param_3 = arcpy.Parameter() param_3.name = u'Comments' param_3.displayName = u'Comments' param_3.parameterType = 'Optional' param_3.direction = 'Input' param_3.datatype = u'String' return [param_1, param_2, param_3] def execute(self, parameters, messages): fc = parameters[0].valueAsText # Feature Layer dospath = parameters[1].valueAsText # dospath comments = parameters[2].valueAsText # comments result = arcpy.GetCount_management(fc) count = int(result.getOutput(0)) if count > 1: arcpy.AddError('SELECT EXACTLY ONE (1) FEATURE') sys.exit(0) #dos drive, path, and filename drive, path_and_file = os.path.splitdrive(dospath) path, file = os.path.split(path_and_file) # http and https drive, path and fileame httpdrive = 'http://gisfiles.neorsd.org' httpsdrive = 'https://arcgis2.neorsd.org/data1' httpfile = file.lower() httppath = path.lower() drawingpath = httpdrive + httppath.replace("\\", "/") + "/" + httpfile drawingsetpath = httpdrive + httppath.replace("\\", "/") + "/" externaldrawingpath = httpsdrive + httppath.replace("\\", "/") + "/" + httpfile fields = ['DRAWING','DRAWINGPATH','DRAWINGSETPATH','EXTERNALDRAWINGPATH', 'COMMENTS'] with arcpy.da.UpdateCursor(fc, fields) as cursor: for row in cursor: row [0] = file row [1] = drawingpath row [2] = drawingsetpath row [3] = externaldrawingpath row [4] = comments cursor.updateRow(row)
أكثر...
Any ideas of what is wrong?
import arcpy, sys, os class Toolbox(object): def __init__(self): self.label = u'Polygon Linker' self.alias = '' self.tools = [PolygonLinker] class PolygonLinker(object): def __init__(self): self.label = u'Polygon Linker' self.description = u'' self.canRunInBackground = False def getParameterInfo(self): # Reference_Polygon_Feature_Class param_1 = arcpy.Parameter() param_1.name = u'Reference_Polygon_Feature_Class' param_1.displayName = u'Reference Polygon Feature Class' param_1.parameterType = 'Required' param_1.direction = 'Input' param_1.datatype = u'GPLayer' # File_to_link_to param_2 = arcpy.Parameter() param_2.name = u'File_to_link_to' param_2.displayName = u'File to link to' param_2.parameterType = 'Required' param_2.direction = 'Input' param_2.datatype = 'DEFile' param_2.filter.list = ['tif', 'tiff', 'pdf'] # Comments param_3 = arcpy.Parameter() param_3.name = u'Comments' param_3.displayName = u'Comments' param_3.parameterType = 'Optional' param_3.direction = 'Input' param_3.datatype = u'String' return [param_1, param_2, param_3] def execute(self, parameters, messages): fc = parameters[0].valueAsText # Feature Layer dospath = parameters[1].valueAsText # dospath comments = parameters[2].valueAsText # comments result = arcpy.GetCount_management(fc) count = int(result.getOutput(0)) if count > 1: arcpy.AddError('SELECT EXACTLY ONE (1) FEATURE') sys.exit(0) #dos drive, path, and filename drive, path_and_file = os.path.splitdrive(dospath) path, file = os.path.split(path_and_file) # http and https drive, path and fileame httpdrive = 'http://gisfiles.neorsd.org' httpsdrive = 'https://arcgis2.neorsd.org/data1' httpfile = file.lower() httppath = path.lower() drawingpath = httpdrive + httppath.replace("\\", "/") + "/" + httpfile drawingsetpath = httpdrive + httppath.replace("\\", "/") + "/" externaldrawingpath = httpsdrive + httppath.replace("\\", "/") + "/" + httpfile fields = ['DRAWING','DRAWINGPATH','DRAWINGSETPATH','EXTERNALDRAWINGPATH', 'COMMENTS'] with arcpy.da.UpdateCursor(fc, fields) as cursor: for row in cursor: row [0] = file row [1] = drawingpath row [2] = drawingsetpath row [3] = externaldrawingpath row [4] = comments cursor.updateRow(row)
أكثر...