0

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:")
 print(count2)
 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",)
 curs.updateRow(row)
 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:")
 print(count3)
 if count3 == count2:
 print("Everything OK!, Please continue.")
 else:
 Selection = arcpy.SelectLayerByLocation_management(lyr1, "ARE_IDENTICAL_TO", lyr3,0,"SWITCH_SELECTION")
 print("Some features not matched, Please review.")
asked Oct 4, 2019 at 16:41

1 Answer 1

2

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

answered Oct 4, 2019 at 20:59
1
  • I also had to write the last selection statement in two lines as shown here Commented Oct 18, 2019 at 9:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.