Solved! Go to Solution.
minValue = arcpy.SearchCursor("Stewardship", "", "", "", "OID A").next().getValue("OID") arcpy.MakeFeatureLayer_management ("Stewardship", "feat_layer") arcpy.SelectLayerByAttribute_management ("feat_layer", "NEW_SELECTION", " [OID] = " + maxValue) Whatever you do now on "feat"layer" will honor the selection if that tool supports it.
maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID D").next().getValue("OBJECTID") arcpy.AddMessage(maxValue)
You could use a cursor with a sort on it:infc = my input feature class myField = field I am after the max value from OID = ObjectID field of my FC. [maxValue = arcpy.SearchCursor(infc, "", "", "", myField+ " D").next().getValue(OID) change the myField field to the one you want the max value from and grab the "OID" of that record as maxValue variable.this would give you the values, could then use that to select by.
I have OBJECTID, not OID, however when I try your code it prints always the first record. I tried both with A and D. I tried sorting by SequenceNumber (numbers from 1 to 8), and I tried sorting by OBJECTID. Which I get is always the first number. So for example, SequenceNumber 1 I get OBJECTID 2451 (object id for sequence number 1) and if I sort by OBJECTID, I get 2445, no matter what (the objectids go from 2445 to 2451). I am using SQL feature class. Any idea why this is happening? Also, you mentioned you can't do anything with a fc for a selection. Is that the same with a selection by location? Because I was able to select by location just using the fc name ("Stewardship), without creating a feature layer. Would you know why that worked? Thank you!!!maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID D").next().getValue("OBJECTID") arcpy.AddMessage(maxValue)
I have OBJECTID, not OID, however when I try your code it prints always the first record. I tried both with A and D. I tried sorting by SequenceNumber (numbers from 1 to 8), and I tried sorting by OBJECTID. Which I get is always the first number. So for example, SequenceNumber 1 I get OBJECTID 2451 (object id for sequence number 1) and if I sort by OBJECTID, I get 2445, no matter what (the objectids go from 2445 to 2451). I am using SQL feature class. Any idea why this is happening? Also, you mentioned you can't do anything with a fc for a selection. Is that the same with a selection by location? Because I was able to select by location just using the fc name ("Stewardship), without creating a feature layer. Would you know why that worked? Thank you!!!maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID D").next().getValue("OBJECTID") arcpy.AddMessage(maxValue)
maxValue = arcpy.SearchCursor(infc, "", "", "", "OBJECTID D").next().getValue("OBJECTID") max Value = 2110 minValue = arcpy.SearchCursor(infc, "", "", "", "OBJECTID A").next().getValue("OBJECTID") min Value = 1
I am actually running the script I am writing so I am not directly using the tool. Not sure why it works.
ExecuteError: Failed to execute. Parameters are not valid. The value cannot be a feature class ERROR 000840: The value is not a Raster Layer. ERROR 000840: The value is not a Mosaic Layer. Failed to execute (SelectLayerByAttribute).