Do you want to actually delete the layer from the geodatabase or remove it from the mxd?
If you just want to remove the layer from your mxd, replace arcpy.Delete_management("CADAnnotation")
with arcpy.mapping.RemoveLayer(df, lyr)
If you want to delete the data source you can do this.
for item in mxds:
print (item)
mxd = arcpy.mapping.MapDocument(item)
df=arcpy.mapping.ListDataFrames(mxd,"Project Area")[0]
for lyr in arcpy.mapping.ListLayers(mxd, "*",df):
if lyr.name == "CADAnnotation":
arcpy.mapping.RemoveLayer(df, lyr)
print(lyr.dataSource)
arcpy.Delete_management(lyr.dataSource)
print("Layer Deleted")
else:
pass
You combine whereClause3 and whereClause4 with the AND operator.
As gm70560 wrote, the variables workforceField, workforceindex are not defined. That's why, first you have to define them. I guess workforceindex is a double or at least a number datatype like farmfieldindex. So you have to Change:
whereClause3 = "\"%s\" = '%s'" % (workforceField, workforceindex)
to:
whereClause3 = "\"%s\" = %s" % (workforceField, workforceindex)
The whereClause4 is not defined (commented out). You have to change
whereClause = "\"%s\" = '%s'" % (farmField, farmfieldindex)
to:
whereClause4 = "\"%s\" = %s" % (farmField, farmfieldindex)
Is that right? (I removed the single quotes for the farmfieldindex)
Another reason for getting an error should be the following:
whereClause3 + "AND" + whereClause4
Is the same like: "\"%s\" = %s" + "AND" + "\"%s\" = %s"
Is the same like: "\"%s\" = %sAND\"%s\" = %s"
Thus, you have no blank between the value (workforceindex) of the first part of the where clause and the AND Operator. Change the Select Layer by Attribute Function to the following and it should work:
arcpy.SelectLayerByAttribute_management(countiesL, "NEW_SELECTION", whereClause3 + " AND " + whereClause4)
If it still not working check the delimiters in the where clause (have a look at the AddFieldDelimiters function)
Best Answer
Assuming you have "LandRecords.GISDBA.Parcels" as a layer in your map document and the layer name is set to "Parcels" you should be able to do this:
Note: my experience so far is changing the map extents automatically refreshes the map. I only call
arcpy.RefreshActiveView()
when I manually manipulate thedf.scale
.