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.
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")
import arcpy field = "RMS" cursor = arcpy.da.UpdateCursor(fc, field, "{0} IS NULL".format(arcpy.AddFieldDelimiters(fc, field))) for row in cursor: row[0] = "" cursor.updateRow(row) del row, cursor
Initially, I was going to create a list, but then determined that I needed to update two fields. So, if I get help with the syntax, I can just recreate the for loop twice. Guess, I could have taken the list out.
The suggested code is not working yet. So, I am going to go through my code and see if something else is missing.
import arcpy field = "RMS" sql = "{0}".format(arcpy.AddFieldDelimiters(fc,field)) + " IS NULL" cursor = arcpy.da.UpdateCursor(fc, field, sql) for row in cursor: row[0] = "" cursor.updateRow(row) del row, cursor.
updateRows = arcpy.da.UpdateCursor(fc, RMS + " IS NULL", "", RMS)
UpdateCursor (in_table, field_names, {where_clause} , {spatial_reference}, {explode_to_points}, {sql_clause}) so maybe something like: updateRows = arcpy.da.UpdateCursor(fc,"RMS",RMS + " IS NULL")
import arcpy RMS = arcpy.GetParameterAsText(0) Type = arcpy.GetParameterAsText(1) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] fc = arcpy.mapping.ListLayers(mxd, "Region", df)[0] #Logic try: whereClause = ''' "RMS" = '{0}' AND "Type" = '{1}' '''.format(RMS, Type) arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", whereClause) df.extent = fc.getSelectedExtent() df.scale = df.scale*1.1 sql = "{0}".format(arcpy.AddFieldDelimiters(fc,field)) + " IS NULL" cursor = arcpy.da.UpdateCursor(fc, field, sql) for row in cursor: row[0] = "" cursor.updateRow(row) del row, cursor except: print arcpy.GetMessages()
Perhaps because it is formatted incorrectly.updateRows = arcpy.da.UpdateCursor(fc, RMS + " IS NULL", "", RMS)UpdateCursor (in_table, field_names, {where_clause} , {spatial_reference}, {explode_to_points}, {sql_clause}) so maybe something like: updateRows = arcpy.da.UpdateCursor(fc,"RMS",RMS + " IS NULL")
It appears as if you where clause and fields are transposed and no quotes around the field attribute so was looking for the variable RMS.
of course, with your where clause, you still need to define RMS, so maybe that part doesn't matter.
R_