fieldList = arcpy.ListFields(fc, "", "String") for field in fieldList: updateRows = arcpy.da.UpdateCursor(fc, RMS + " IS NULL", "", RMS) for updateRow in updateRows: updateRow.setValue(RMS, "") updateRows.updateRow(updateRow) del row, cursor
Solved! Go to Solution.
I copied the data from the Type field to a new field, named Classification. The Regions layer is a feature class.
print RMS
print Classification
After running the print RMS & Classification the script completes with no errors or results. I just receive the typical start time, end time, running, and completed notifications. If I add arcpy.AddMessage("Good") after the
RMS = arcpy.GetParameterAsText(0)
Classification = arcpy.GetParameterAsText(1)
Then, I receive the same as before with "Good" added. So, the input parameters seem to be ok.
arcpy.AddMessage("Good")
arcpy.AddMessage(str(RMS)) arcpy.AddMessage(str(Classification))
import arcpy RMS = arcpy.GetParameterAsText(0) Classification = arcpy.GetParameterAsText(1) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] fc = arcpy.mapping.ListLayers(mxd, "Region", df)[0] arcpy.AddMessage(str(RMS)) arcpy.AddMessage(str(Classification)) try: whereClause = ''' "RMS" = '{0}' AND "Classification" = '{1}' '''.format(RMS, Classification) arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", whereClause) df.extent = fc.getSelectedExtent() df.scale = df.scale*1.1 cursor = arcpy.da.UpdateCursor(fc,"RMS", RMS + " IS NULL") for row in cursor: row[0] = "" cursor.updateRow(row) del row, cursor except: print arcpy.GetMessages()
import arcpy RMS = arcpy.GetParameterAsText(0) Classification = arcpy.GetParameterAsText(1) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] fc = arcpy.mapping.ListLayers(mxd, "Region", df)[0] arcpy.AddMessage(str(RMS)) arcpy.AddMessage(str(Classification)) #Logic try: whereClause = ''' "RMS" = '{0}' AND "Classification" = '{1}' '''.format(RMS, Classification) arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", whereClause) df.extent = fc.getSelectedExtent() df.scale = df.scale*1.1 sql = "{0}".format(arcpy.AddFieldDelimiters(Region, RMS, Classification)) + " IS NULL" cursor = arcpy.da.UpdateCursor("Region", ["RMS", "Classification"], sql) for row in cursor: row[0] = "" cursor.updateRow(row) del row, cursor except: print arcpy.GetMessages()
The values entered are returned. I entered 1 for RMS and F for Classification.
The initial whereClause runs fine, until a null value is encountered. I believe the issue is still with the UpdateCursor. I have gone back and attempted to work with the previous suggestions, but to not avail. The results are still the same, no errors, and no results. I know how to fix the null vs blank problem using field calculator, but not with a script. Other suggestions?
import arcpy RMS = arcpy.GetParameterAsText(0) Classification = arcpy.GetParameterAsText(1) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] fc = arcpy.mapping.ListLayers(mxd, "Region", df)[0] arcpy.AddMessage(str(RMS)) arcpy.AddMessage(str(Classification)) #Logic try: whereClause = ''' "RMS" = '{0}' AND "Classification" = '{1}' '''.format(RMS, Classification) arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", whereClause) df.extent = fc.getSelectedExtent() df.scale = df.scale*1.1 arcpy.SelectLayerByAttribute_management(fc, "CLEAR_SELECTION", whereClause) sql = "{0}".format(arcpy.AddFieldDelimiters(Region, RMS, Classification)) + " IS NULL" # not sure what the output of this is,is it valid sql? in either case, Region variable is not defined cursor = arcpy.da.UpdateCursor(fc, "RMS", sql) # the region layer has been set to variable fc. for row in cursor: row[0] = "" cursor.updateRow(row) del row, cursor except: print arcpy.GetMessages()
arcpy.CalculateField_management(fc, "RMS", "\\"", "PYTHON_9.3")