POST
|
I am pretty sure there is something wrong with the way the SDE feature class fields are being referenced. I have tried several combinations of single and double quotes with no change in result. Any assistance debuging this would be greatly appreciated. Result when executed in Python Shell: >>> ================================ RESTART ================================ >>> Script starting... Checking source data. Traceback (most recent call last): File "//server19/GIS/Projects/CAD Updates/Master Streets Update/Debugging.py", line 44, in <module> DRows = arcpy.UpdateCursor(DestFC, (DestMFld + ' = ' + str(dID))) File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 841, in UpdateCursor return gp.updateCursor(*args) File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 362, in updateCursor self._gp.UpdateCursor(*gp_fixargs(args))) RuntimeError: ERROR 999999: Error executing function. Attribute column not found [Microsoft SQL Server Native Client 10.0: Invalid column name 'None'.] [production.SDE.Streets_Master] >>> Source Script (executed in Python Shell) import arcpy import datetime print('Script starting...') #Default Values SourceFC = '//server19/gis/Projects/CAD Updates/Master Streets Update/StreetsUpdate_2012-05-22_1701.gdb/Deltas' SourceMFld = 'MC911ID' SourceExp = '1 = 1' DestFC = 'Database Connections\Production_Editing.sde\production.SDE.CAD_data\production.SDE.Streets_Master' DestMFld = 'ExternalStreetKey' DestExp = '1 = 1' DestCom = 'Notes' #ArcGIS Script inputs ##SourceFC = arcpy.GetParameterAsText(0) ##SourceMFld = arcpy.GetParameterAsText(1) ##SourceExp = arcpy.GetParameterAsText(2) ##DestFC = arcpy.GetParameterAsText(3) ##DestMFld = arcpy.GetParameterAsText(4) ##DestExp = arcpy.GetParameterAsText(5) ##DestCom = arcpy.GetParameterAsText(6) Source = SourceFC Destination = DestFC #Set up variables sShape = arcpy.Describe(SourceFC).shapeFieldName dShape = arcpy.Describe(DestFC).shapeFieldName SRows = arcpy.SearchCursor(SourceFC) dcount = 0 bcount = 0 SourceLoopFlag = 0 DestinationLoopFlag = 0 MatchFlag = 0 #Loop through features, copy geometry as appropriate for SRow in SRows: if SourceLoopFlag == 0: SourceLoopFlag = 1 print("Checking source data. ") dID = SRow.getValue(SourceMFld) DRow, DRows = None, None DRows = arcpy.UpdateCursor(DestFC, (DestMFld + ' = ' + str(dID))) for DRow in DRows: if DestinationLoopFlag == 0: DestinationLoopFlag = 1 print("Checking destination data. ") bID = DRow.getValue(DestMFld) if bID == dID: if MatchFlag == 0: MatchFlag = 1 print("Match found. ") updated = 'Updated ' + str(datetime.datetime.now()) DRow.setValue(DestCom, updated ) DRow.setValue(dShape, SRow.getValue(sShape)) DRows.updateRow(DRow) bcount = bcount +1 break del DRow del DRows dcount = dcount +1 del SRow del SRows print('Source rows processed: ' + str(dcount)) print('Destination rows updated: ' + str(bcount)) arcpy.AddMessage('Source rows processed: ' + str(dcount)) arcpy.AddMessage('Destination rows updated: ' + str(bcount)) print SourceLoopFlag print DestinationLoopFlag print MatchFlag #Send messages to the results window. if SourceLoopFlag == 0: arcpy.AddWarning('No source rows were checked.') if DestinationLoopFlag == 0: arcpy.AddWarning('No destination rows were checked.') if MatchFlag == 0: arcpy.AddWarning('No destination rows were updated.') print('Script Complete')
... View more
06-06-2012
01:28 PM
|
0
|
1
|
4460
|
POST
|
I have changed course and have written the script to run independant of ArcMap and the problem seems to have resolved. Thanks for yout assistance.
... View more
06-06-2012
01:01 PM
|
0
|
0
|
284
|
POST
|
I'm going to try the funtions suggestion. As for the TestSchemaLock it always returns FALSE, but with the code below it still executes and updates the geometry. The diffference is I am using shapefiles now. I know my process is solid, it is just dealing with the locks and different data sources that drives me nuts. I stripped down the script from the original post to eliminate possible complications. Specifically the Try: block. I occasionally would get a warning stating the Exception class was not supported. I switched the source of the layers referenced in the script back to the File Geodatabase and ran the script again. ArcMap immediately folds and crashes. import arcpy
deltas = arcpy.mapping.Layer("Deltas")
base = arcpy.mapping.Layer("Base")
lockTest = arcpy.TestSchemaLock(base)
if lockTest:
print('Schema is not locked')
else:
print('Schema IS locked')
dShape = arcpy.Describe(deltas).shapeFieldName
bShape = arcpy.Describe(base).shapeFieldName
drows = arcpy.SearchCursor(deltas)
dcount = 0
bcount = 0
arcpy.SelectLayerByAttribute_management("Base","CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management("Deltas","CLEAR_SELECTION")
for drow in drows:
dID = drow.MC911_ID
print("drow-" + str(dID))
brow, brows = None, None
brows = arcpy.UpdateCursor(base,'"MC911_ID" = ' + str(dID))
for brow in brows:
bID = brow.MC911_ID
brow.MC911ID = 'Row Checked: ' + str(datetime.datetime.now())
brows.updateRow(brow)
bcount = bcount +1
if bID == dID:
brow.setValue("MC911ID", 'Matched')
brow.setValue(bShape, drow.getValue(dShape))
brows.updateRow(brow)
print("Match-" + str(bID))
break
del brow
del brows
dcount = dcount +1
del drow
del drows
print dcount
print bcount
print('Script Complete')
... View more
06-05-2012
01:19 PM
|
0
|
0
|
284
|
POST
|
I have been having a heck of a time trying to get this script to run. The best I get is it will run once, and crash the app the second time. This makes me think it is a locking issue. I haven't been able to get a clear reference on how this is handled in python / arcpy. I am running 10.0 sp3, the referenced layers are in a file geodatabase for now. I eventually wish to modify a SDE feature class, but I want to work out the bugs before I point this at my database. The commented out lines are my attempts to isolate problematic portions of script. The long term goal of this script will be to copy the geometry from one feature class to another with a matching "MC911_ID" field, but I am stuck here thus far. Any assistance is greatly appreciated. import arcpy
try:
drow, drows = None, None
deltas = arcpy.mapping.Layer("Deltas")
base = arcpy.mapping.Layer("Baseline")
dShape = arcpy.Describe(deltas).shapeFieldName
bShape = arcpy.Describe(base).shapeFieldName
drows = arcpy.SearchCursor("Deltas")
dcount = 0
bcount = 0
arcpy.SelectLayerByAttribute_management("Baseline","CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management("Deltas","CLEAR_SELECTION")
for drow in drows:
dID = drow.MC911_ID
print("drow-" + str(dID))
brow, brows = None, None
brows = arcpy.UpdateCursor("Baseline",'"MC911_ID" = ' + str(dID))
for brow in brows:
bID = brow.MC911_ID
## brow.MC911ID = 'Row Checked: ' + str(datetime.datetime.now())
brows.updateRow(brow)
bcount = bcount +1
if bID == dID:
## brow.setValue("MC911ID", 'Matched')
## brows.updateRow(brow)
print("Match-" + str(bID))
## brows.close()
break
del brow
del brows
dcount = dcount +1
## drows.close()
print dcount
print bcount
print('Script Complete')
except Exception as e:
if not arcpy.GetMessages() == "":
arcpy.AddMessage(arcpy.GetMessages(2))
print("I am so sorry, there is a problem...")
print e.message
print dcount
print bcount
finally:
# Regardless of whether the script succeeds or not, delete
# the row and cursor
#
if drow:
del drow
if drows:
del drows
if deltas:
del deltas
if base:
del base
... View more
06-05-2012
11:04 AM
|
0
|
3
|
541
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|