if result > 1: maxValue4 = arcpy.SearchCursor("TMP", "", "", "", "SequenceNumber D").next().getValue("SequenceNumber") arcpy.AddMessage(str(maxValue4)) query = "SequenceNumber = " arcpy.SelectLayerByAttribute_management("TMP", "SUBSET_SELECTION", "SequenceNumber = " + str(maxValue4)) result = int(arcpy.GetCount_management("TMP").getOutput(0))
Solved! Go to Solution.
import arcpy, os from arcpy import da ws = r'D:\update\wch_updated2.gdb' arcpy.env.workspace = ws arcpy.env.overwriteOutput = True build_lyr = "build_lyr" field = "rec" maxValue = 14 arcpy.MakeFeatureLayer_management("buildings", "build_lyr") sqlFieldName = arcpy.AddFieldDelimiters("build_lyr", field) expr = sqlFieldName + " = " + str(maxValue) arcpy.SelectLayerByAttribute_management ("build_lyr", "NEW_SELECTION", expr) with da.SearchCursor(build_lyr,['rec']) as cursor: for row in cursor: print str(row[0])
import arcpy, os from arcpy import da ws = r'D:\update\wch_updated2.gdb' arcpy.env.workspace = ws arcpy.env.overwriteOutput = True build_lyr = "build_lyr" field = "rec" maxValue = 14 arcpy.MakeFeatureLayer_management("buildings", "build_lyr") sqlFieldName = arcpy.AddFieldDelimiters("build_lyr", field) expr = sqlFieldName + " = " + str(maxValue) arcpy.SelectLayerByAttribute_management ("build_lyr", "NEW_SELECTION", expr) with da.SearchCursor(build_lyr,['rec']) as cursor: for row in cursor: print str(row[0])
import arcpy, os ws = r'D:\update\wch_updated.gdb' arcpy.env.workspace = ws datasets = arcpy.ListDatasets() excludeList = ['Base','OSEGrids','River_Flows','Utilities','Wells','MR'] # Overwrite pre-existing files arcpy.env.overwriteOutput = True datasets.append("") # this appends a blank onto the dataset list so it picks up FC's in the base FGDB level. for ds in datasets: if ds not in excludeList: # only do this to DS's not in my exclude list print "working on ",ds fcs = arcpy.ListFeatureClasses("","",ds) for fc in fcs: print "creating field maps" fieldmappings = arcpy.FieldMappings() fieldmappings.addTable(fc) for field in arcpy.ListFields(fc, "", "String"): #Find all fields other than type of ObjectId and Geometry # if (field.type != 'OID') & (field.type != 'Geometry'): # I commented this as my ListFields limits to "String" fields only #Create a new Field Map Object and populate it print "populating object for ",fc fldmap_Changed = arcpy.FieldMap() fieldName = field.name fldmap_Changed.addInputField(fc, fieldName) #Get a new field object from the Field Map Object and set the Allow Null Property to False print "setting to false" fld_Changed = fldmap_Changed.outputField fld_Changed.isNullable = False #Add the field back to the Field Map Object fldmap_Changed.outputField = fld_Changed #Find and replace the current field map in the Field Mappings with the new Field Map Object print "replacing current field map" index = fieldmappings.findFieldMapIndex(fieldName) fieldmappings.replaceFieldMap(index, fldmap_Changed) del fldmap_Changed, fld_Changed print "outputting fc ",fc arcpy.FeatureClassToFeatureClass_conversion(ds + os.sep + fc, arcpy.env.workspace, ds + os.sep + fc + "Copy1", "", fieldmappings) #### ### The script makes a copy in each dataset of the original. ### This section removes the original and renames the copy to the original name #### for fc in fcs: if arcpy.Exists(ds + os.sep + fc): print "deleting ",ds + os.sep + fc arcpy.Delete_management(ds + os.sep + fc) print "creating ",fc,"from ",ds + os.sep + fc + "Copy1" arcpy.FeatureClassToFeatureClass_conversion(ds + os.sep + fc + "Copy1", arcpy.env.workspace, ds + os.sep + fc, "") arcpy.Delete_management(ds + os.sep + fc + "Copy1") del fieldmappings arcpy.Compact_management(ws) # compact FGDB to removed locks and optimize performance