rows = arcpy.UpdateCursor("Assets") for row in rows: if row.Processed == "N" and row.Asset_ID == "Asset_Unprocessed.Asset_ID": row.Processed = "Y" rows.updateRow(row) del row del rows
table = 'assets_unprocessed' assetIDList = [] rows = arcpy.SearchCursor(table) for row in rows: assetIDList.append(row.Asset_ID) del row, rows table2 = 'assets' for ID in assetIDList: rows = arcpy.UpdateCursor(table2) for row in rows: if row.Asset_ID == ID: row.Processed = 'Y' rows.updateRow(row) del row, rows print 'finished'
import arcpy from arcpy import env import datetime import os env.workspace = "c:\Users\matt\Desktop\Projects\Assets\Assets.mdb" #Make a TableView of Non-Spatial Asset records that need to be processed arcpy.MakeQueryTable_management (["Assets"], "Asset_Line", "ADD_VIRTUAL_KEY_FIELD", "",[["Asset_ID"], ["Ditch_ID"], ["Begin_Station"], ["End_Station"]], "[Assets.Processed] <> 'Y'") #Add queried data to Assets_Unprocessed table-to be used by ArcObjects utility to create spatial features arcpy.Append_management ("Asset_Line", "Assets_Unprocessed") #Copy attribute data to spatial Asset features #Call ArcObjects utility to snap 'out of ditch' linear features to spatial Asset features #Call ArcObjects utility to snap related assets to spatial Asset features au = "Assets_Unprocessed" lstIds = [] fld = "Asset_ID" auRows = arcpy.SearchCursor(au) for row in auRows: lstIds.append(row.Asset_ID) del row, auRows table2 = "Assets" for ID in lstIds: rows = arcpy.UpdateCursor(table2) for row in rows: if row.Asset_ID == ID: row.Processed = 'Y' rows.updateRow(row)
The latest reply mentioned using a SearchCursor without the with...as statement, but I cannot get that to work either (error returns 'Cursor' object has no attribute 'Asset_ID' when I run the SearchCursor code:
au = "Assets_Unprocessed" lstIds = [] fld = "Asset_ID" auRows = arcpy.SearchCursor(au) for row in auRows: lstIds.append(auRows.Asset_ID)
Greg,Thanks for the input, I see how that could resolve my issue. I tried running that SearchCursor section of code you supplied, but an error was returned: Runtime error <type 'exceptions.AttributeError'>: 'Cursor' object has no attribute '__exit__'I am unfamiliar with the with...as statement so I'm not sure what is missing or needed here. I understand the process of building a list of Asset_ID's from Assets_Unprocessed then searching for records in Assets with those Asset_ID's, but it seems I'm having difficulty in first building that list with the SearchCursor and the use of the with...as statement.
au = "Assets_Unprocessed" fld = "Asset_ID" lstIds = [] auRows = arcpy.SearchCursor(au) for row in auRows: lstIds.append(auRows.Asset_ID) del auRows del row try: aRows = arcpy.UpdateCursor("Assets") for row in aRows: if row.Processed == "N" and row.Asset_ID in lstIds: row.Processed = "Y" aRows.update(row) except Exception as e: print e.message #do whatever del aRows del row
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.