I have a button where it first calculate no of features in a specific layer and then runs the "are_identical_to" and update "D". After that it checks if the no of counts in two layers is same? If not, then runs the "are_identical_to" on two different layers and should show up the selected features in my data frame.

However it never shows the selected features in data frame or attribute table?

How can I achieve this.

code is shown below:

import arcpy
import pythonaddins

class Check1(object):
    """Implementation for Preproduction_Check_addin.Check1 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        lyr1 = ""
        lyr2 = ""
        lyr3 = ""
        result2 = ""
        result3 = ""
        count2 = ""
        count3 = ""
        mxd = arcpy.mapping.MapDocument("CURRENT")
        layers = arcpy.mapping.ListLayers(mxd)
        for layer in layers:
            if layer.isFeatureLayer and layer.workspacePath != "":
                if "edits" in layer.name:
                    lyr1 = layer
                elif "fresh" in layer.name:
                    lyr2 = layer
                    result2 = arcpy.GetCount_management(lyr2.dataSource)
                    count2 = int(result2.getOutput(0))
                    print("Total Features in fresh data:")
                elif "D" in layer.name:
                    lyr3 = layer

        Selection = arcpy.SelectLayerByLocation_management(lyr1, "ARE_IDENTICAL_TO", lyr2)
        if arcpy.Describe(lyr1.name).FIDSet:
            with arcpy.da.UpdateCursor(lyr1.name, "Update") as curs:
                for row in curs:
                    row = ("D",)
                del curs
                del row
                print("Remark 'D' Updated")

        result3 = arcpy.GetCount_management(lyr3.dataSource)
        count3 = int(result3.getOutput(0))

        print("Total features in 'D' Layer:")

        if count3 == count2:
            print("Everything OK!, Please continue.")
            Selection = arcpy.SelectLayerByLocation_management(lyr1, "ARE_IDENTICAL_TO", lyr3,0,"SWITCH_SELECTION")
            print("Some features not matched, Please review.")

Try adding arcpy.RefreshActiveView() after applying the selection.

  • I also had to write the last selection statement in two lines as shown here – Keshav Sharma Oct 18 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.