Automatically applying selection of feature to related table attributes?

1912
3
Jump to solution
12-31-2013 09:43 AM
NoahWard
New Contributor II
Alright, so this might be an ignorant question, but I am sort of stuck with this issue at the moment.

I have a GDB with a feature class and a stand alone table. I have created a relationship class that is 1-M. When using the identify tool or related tables button within the attribute table, the related features/attributes are correctly selected. What I am looking for is to be able to simply select the object in the feature class on the map, and it automatically apply that selection to the related stand alone table so that it would reflect every attribute associated with the previously selected object.

Is there just a setting I am missing? My relationship class setup is obviously functional. Everything I have researched implies that is how it should be working naturally, but mine is not.

Any ideas?
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
One way to could accomplish this is by creating a python add-in tool.  The only thing is that you will need to specify the layer and table that participate within the relationship.  Here is an example of an add-in that draws a rectangle, selects the features from a layer in the MXD called 'Airports' and then selects records from the related table ('Districts').

import arcpy import pythonaddins  class ToolClass2(object):     """Implementation for UserData2_addin.tool (Tool)"""     def __init__(self):         self.cursor = 0         self.enabled = True         self.shape = "Rectangle"      def onRectangle(self, rectangle_geometry):         #Create Polygon from drawn extent         extent = rectangle_geometry         XMAX = extent.XMax         XMIN = extent.XMin         YMAX = extent.YMax         YMIN = extent.YMin         pnt1 = arcpy.Point(XMIN, YMIN)         pnt2 = arcpy.Point(XMIN, YMAX)         pnt3 = arcpy.Point(XMAX, YMAX)         pnt4 = arcpy.Point(XMAX, YMIN)         array = arcpy.Array()         array.add(pnt1)         array.add(pnt2)         array.add(pnt3)         array.add(pnt4)         array.add(pnt1)         polygon = arcpy.Polygon(array)         #Select features that intersect drawn Polygon         mxd = arcpy.mapping.MapDocument("CURRENT")         df = arcpy.mapping.ListDataFrames(mxd)[0]         for layer in arcpy.mapping.ListLayers(mxd, "Airports", df):             arcpy.SelectLayerByLocation_management(layer, "INTERSECT", polygon, "#", "NEW_SELECTION")             items = []             #Append primary key values to list             with arcpy.da.SearchCursor(layer, ["District"]) as cursor:                 for row in cursor:                     items.append(row[0])             #Remove duplicates from list             items = dict.fromkeys(items)             items = items.keys()         for table in arcpy.mapping.ListTableViews(mxd, "Districts", df):             #Clear selection if one exists             try:                 arcpy.SelectLayerByAttribute_management(table, "CLEAR_SELECTION")             except:                 pass             for item in items:                 #Select records in foreign key                 arcpy.SelectLayerByAttribute_management(table, "ADD_TO_SELECTION", "District = '" + item + "'")

View solution in original post

0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Noah,

After you select a feature, open the attribute table and at the top click on the tool 'Related Tables' (2nd tool from the left).  This will list your related tables.  Select the table and it will show the related records.
0 Kudos
NoahWard
New Contributor II
Jake,

Thanks for your quick reply. That is currently how I am accessing the related info, but from your response I am assuming there is not a way for it to just automatically select everything related in both tables when the "Select Features" tool is used? For example, I have the destination table open, and select an origin feature. Nothing in the destination table is selected unless I open the origin table and then use the "Related Tables" tool. The goal is for it to select the realted attributes in the destination stand alone table without any other processes.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
One way to could accomplish this is by creating a python add-in tool.  The only thing is that you will need to specify the layer and table that participate within the relationship.  Here is an example of an add-in that draws a rectangle, selects the features from a layer in the MXD called 'Airports' and then selects records from the related table ('Districts').

import arcpy import pythonaddins  class ToolClass2(object):     """Implementation for UserData2_addin.tool (Tool)"""     def __init__(self):         self.cursor = 0         self.enabled = True         self.shape = "Rectangle"      def onRectangle(self, rectangle_geometry):         #Create Polygon from drawn extent         extent = rectangle_geometry         XMAX = extent.XMax         XMIN = extent.XMin         YMAX = extent.YMax         YMIN = extent.YMin         pnt1 = arcpy.Point(XMIN, YMIN)         pnt2 = arcpy.Point(XMIN, YMAX)         pnt3 = arcpy.Point(XMAX, YMAX)         pnt4 = arcpy.Point(XMAX, YMIN)         array = arcpy.Array()         array.add(pnt1)         array.add(pnt2)         array.add(pnt3)         array.add(pnt4)         array.add(pnt1)         polygon = arcpy.Polygon(array)         #Select features that intersect drawn Polygon         mxd = arcpy.mapping.MapDocument("CURRENT")         df = arcpy.mapping.ListDataFrames(mxd)[0]         for layer in arcpy.mapping.ListLayers(mxd, "Airports", df):             arcpy.SelectLayerByLocation_management(layer, "INTERSECT", polygon, "#", "NEW_SELECTION")             items = []             #Append primary key values to list             with arcpy.da.SearchCursor(layer, ["District"]) as cursor:                 for row in cursor:                     items.append(row[0])             #Remove duplicates from list             items = dict.fromkeys(items)             items = items.keys()         for table in arcpy.mapping.ListTableViews(mxd, "Districts", df):             #Clear selection if one exists             try:                 arcpy.SelectLayerByAttribute_management(table, "CLEAR_SELECTION")             except:                 pass             for item in items:                 #Select records in foreign key                 arcpy.SelectLayerByAttribute_management(table, "ADD_TO_SELECTION", "District = '" + item + "'")
0 Kudos