I am trying to create a custom tool via python script that selects features in multiple fc's within a feature dataset that are missing values, then from the selected features, creates two outputs: one for points and one for lines. I also want the outputs to have the following fields: OBJECTID, TYPEOFFEATURE, and WHATISMISSING, with the fields populated with their respective attributes. For example, WHATISMISSING should have the field from the fc that has null values and TYPEOFFEATURE should have the fc that . I am not sure how to create two separate outputs determined by the feature type or how to create the fields in them.
This is what I have so far. BTW the datasets are in an enterprise geodatabase so if my workspace is the wrong syntax, please let me know:
import arcpy
# Set the workspace for ListFeatureClasses
arcpy.env.workspace = r"C:\DatabaseCon\GIS.sde"
# Use the ListFeatureClasses function to return a list of feature classes.
fc = list(set(arcpy.ListFeatureClasses("ARCFM.Light", "Point", feature_dataset="ARCFM.ElectricDataset")) | set(arcpy.ListFeatureClasses("ARCFM.Pole", "Point", feature_dataset="ARCFM.ElectricDataset")) | set(arcpy.ListFeatureClasses("ARCFM.SurfaceStructure", "Line", feature_dataset="ARCFM.ElectricDataset")) | set(arcpy.ListFeatureClasses("ARCFM.UndergroundStructure", "Line", feature_dataset="ARCFM.ElectricDataset")))
# loop through the list of feature classes, select by attribute depending on the fc, and export the selected features to a shapefile.
for ifc in fc:
if ifc = "ARCFM.Light":
arcpy.management.SelectLayerByAttribute(ifc, '"LIGHTTYPE" IS NULL')
elif ifc = "ARCFM.Pole":
arcpy.management.SelectLayerByAttribute(ifc, '"Subtype" IS NULL')
elif ifc = "ARCFM.SurfaceStructure":
arcpy.management.SelectLayerByAttribute(ifc, '"Subtype" IS NULL')
elif ifc = "ARCFM.UndergroundStructure":
arcpy.management.SelectLayerByAttribute(ifc, '"Subtype" IS NULL')
# create layer from selection
for mfl in fc:
if mfl.arcpy.management.ListDatasets.feature_type = "POINT":
arcpy.management.MakeFeatureLayer(ARCFM.Light,
"r"C:\DatabaseConnection\DirectConnectGISPROD.sde\points_missing_features, "", "",
"OBJECTID", "TYPEOFFEATURE", "WHATISMISSING") |
arcpy.management.MakeFeatureLayer(ARCFM.Pole,
"r"C:\DatabaseConnection\DirectConnectGISPROD.sde\points_missing_features, "", "",
"OBJECTID", "TYPEOFFEATURE", "WHATISMISSING")
else:
arcpy.management.MakeFeatureLayer(ARCFM.SurfaceStructure,
"r"C:\DatabaseConnection\DirectConnectGISPROD.sde\lines_missing_features, "", "",
"OBJECTID", "TYPEOFFEATURE", "WHATISMISSING") |
arcpy.management.MakeFeatureLayer(ARCFM.UndergroundStructure,
"r"C:\DatabaseConnection\DirectConnectGISPROD.sde\lines_missing_features, "", "",
"OBJECTID", "TYPEOFFEATURE", "WHATISMISSING")
I know I am missing things like determining constraints for the fields in the output fc's, I just don't know how to do that in Python.