import arcpy arcpy.env.workspace = "X:" ws = arcpy.ListWorkspaces("*","Folder") for w in ws: arcpy.env.workspace = w gdb = arcpy.ListWorkspaces("*", "Access") for fc in gdb: arcpy.env.workspace = fc fcl = arcpy.ListDatasets("*", "Feature") for fcc in fcl: arcpy.env.workspace = fcc fccl = arcpy.ListFeatureClasses("*", "All") print fccl
field = "Label" value = "drillhole" for fc in fccl: try: s_curs = arcpy.SearchCursor(fc,"%s = '%s'" % (field,value),"","Label") for row in s_curs: # do something as each row should be a drillhole
...continue indentation from previous part of script... fccl = arcpy.ListFeatureClasses("*", "All") for featureclass in fccl: rows = arcpy.SearchCursor(featureclass) for row in rows: drillhole = row.Label
Not quite sure what you are asking. What about the attribute 'drillhole' in the 'Label' field do you want to know? The OID? Number of occurrences? Here's an example of identifying the row and then you can do what you want from there.field = "Label" value = "drillhole" for fc in fccl: try: s_curs = arcpy.SearchCursor(fc,"%s = '%s'" % (field,value),"","Label") for row in s_curs: # do something as each row should be a drillhole
Thanks for you help Mathew. I am trying to find out which feature classes in a directory with 200+ folders has drillholes. I tried the code you gave me but this was what was returned:
General function failure [ballinp_1]
Too few parameters. Expected 1.
That would probably be because there was no except statement added at the end. A simpler way to go about it might be to make a temp feature layer from each fc and do a select by attribute to see if get count returns anything.
for w in ws: arcpy.env.workspace = w gdb = arcpy.ListWorkspaces("*", "Access") for fc in gdb: arcpy.env.workspace = fc fcl = arcpy.ListDatasets("*", "Feature") for fcc in fcl: arcpy.env.workspace = fcc fccl = arcpy.ListFeatureClasses("*", "All") for stil in fccl: arcpy.env.workspace = fccl stil = arcpy.SaveToLayerFile_management("fccl","fccl2","")
import arcpy arcpy.env.overwriteOutput = True tempLayer = r"in_memory\templayer" field = "Label" value = "drillhole" where = "%s = '%s'" % (field,value) dhList = [] for w in ws: arcpy.env.workspace = w gdb = arcpy.ListWorkspaces("*", "Access") for fc in gdb: arcpy.env.workspace = fc fcl = arcpy.ListDatasets("*", "Feature") for fcc in fcl: arcpy.env.workspace = fcc fccl = arcpy.ListFeatureClasses("*", "All") for stil in fccl: arcpy.MakeFeatureLayer_management(stil, tempLayer, where) arcpy.SelectLayerByAttribute_management(tempLayer) count = int(arcpy.GetCount_management(tempLayer).getOutput) if count > 0: dhList.append(stil) for item in dhList: print item
import arcpy arcpy.env.workspace = "X:" ws = arcpy.ListWorkspaces("*","Folder") arcpy.env.overwriteOutput = True tempLayer = r"in_memory\templayer" field = "Label" value = "drillholes" where = "%s = '%s'" % (field,value) dhList = [] for w in ws: arcpy.env.workspace = w gdb = arcpy.ListWorkspaces("*", "Access") for fc in gdb: arcpy.env.workspace = fc fcl = arcpy.ListDatasets("*", "Feature") for fcc in fcl: arcpy.env.workspace = fcc fccl = arcpy.ListFeatureClasses("*", "All") for stil in fccl: arcpy.MakeFeatureLayer_management(stil, tempLayer, where) arcpy.SelectLayerByAttribute_management(tempLayer,"SUBSET_SELECTION") count = str(arcpy.GetCount_management(tempLayer).getOutput) if count > 0: dhList.append(stil) for item in dhList: print item