I have two layers that are related. My current manual process is as follow;

a. Add the layer 1 to the table of contents

b. Open the attribute table then Switch selection to select all layer 1 records

c. Click relates and select layer 2 This will select all layer 2 records related to the layer 1

d. Switch selection This will display all layer 2 records not related to the layer 1

e. Export the table to excel

I want to automate this using ModelBuilder.

This is where I am using ModelBuilder;

Layer 1 > Select Layer By Attribute (Switch selection) > Calculate Field (I require a python script that is able select all related layer 2 records) > Select Layer By Attribute (Switch Selection) > Export to Excel

  • You want to export records that are in layer 2, and not in layer 1?
    – BERA
    Feb 13, 2018 at 9:42
  • Yes, apologies, should have clarified. However that aspect i can do, its just the 'relates' i am stuck on.
    – A.T
    Feb 13, 2018 at 9:44
  • There is no geo-processing tool in ArcMap that can pass the selection from one table to another. The only way I can think this can be done is with scripting.
    – Hornbydd
    Feb 13, 2018 at 9:48
  • I have come across calculate field and search cursor (help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…) And it has a section to input a python script.
    – A.T
    Feb 13, 2018 at 9:50
  • 1
    @A.T This script will select unique rows in layer 2: jpst.it/1aWPl . Paste in Python window and call function, for example like this: findunique("Points1","Points2","Id")
    – BERA
    Feb 13, 2018 at 10:02

1 Answer 1


You can solve your task using Python without the need for relates or joins. Function below will select rows from layer 2 that are not in layer 1 based on a common field. The selection can then be exported to Excel. Let me know if you only want to use ModelBuilder and I will delete my answer.

import arcpy

def findunique(layer1, layer2, idfield):
    #Select rows from layer2 that are not in layer1 based on a idfield
    layer1_ids = [i[0] for i in arcpy.da.SearchCursor(layer1, idfield)]
    oids_to_select = []
    with arcpy.da.SearchCursor(layer2,['OID@',idfield]) as cursor:
        for row in cursor:
            if row[1] not in layer1_ids:
    sql = """{0} IN ({1})""".format(arcpy.AddFieldDelimiters(layer2,arcpy.Describe(layer2).OIDFieldName),", ".join(map(str,oids_to_select)))

enter image description here

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.