arcpy mapping: getting the selected features of one data frame selected in another df

1815
1
Jump to solution
11-27-2013 05:28 AM
jasonfargo
New Contributor
does anyone have example code showing how to get the features that are already selected in one data frame to also select the same set of features that are in a different data frame?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor
Jason,

Here is the code you require, take note of assumptions and adjusted accordingly.

# Description: Passes selection from one DataFrame to another for the same layer. # Usage:       Designed to be run in Python Command line window. Code assumes layers are Shapefiles and a selection actually exists # Author:      Duncan Hornby # Created:     27/11/13 import arcpy   # Get map document and list of DataFrames, code assumes only 2 exist mxd = arcpy.mapping.MapDocument("CURRENT") l = arcpy.mapping.ListDataFrames(mxd)   # Get DataFrames df1 = l[0] df2 = l[1]   # Get layer from first dataframe and create a list of select FIDs layername = "yr89_clipped_water_as_polygons" # Change this to your layer name l1 = arcpy.mapping.ListLayers(mxd,layername,df1)[0] d = arcpy.Describe(l1) fids = d.FIDSet toselect = fids.replace(";",",")   # Get second identical layer in second dataframe and do selection l2 = arcpy.mapping.ListLayers(mxd,layername,df2)[0] sQuery = '"FID" IN (' + toselect + ')' arcpy.SelectLayerByAttribute_management(l2,"NEW_SELECTION",sQuery)


Duncan

View solution in original post

0 Kudos
1 Reply
DuncanHornby
MVP Notable Contributor
Jason,

Here is the code you require, take note of assumptions and adjusted accordingly.

# Description: Passes selection from one DataFrame to another for the same layer. # Usage:       Designed to be run in Python Command line window. Code assumes layers are Shapefiles and a selection actually exists # Author:      Duncan Hornby # Created:     27/11/13 import arcpy   # Get map document and list of DataFrames, code assumes only 2 exist mxd = arcpy.mapping.MapDocument("CURRENT") l = arcpy.mapping.ListDataFrames(mxd)   # Get DataFrames df1 = l[0] df2 = l[1]   # Get layer from first dataframe and create a list of select FIDs layername = "yr89_clipped_water_as_polygons" # Change this to your layer name l1 = arcpy.mapping.ListLayers(mxd,layername,df1)[0] d = arcpy.Describe(l1) fids = d.FIDSet toselect = fids.replace(";",",")   # Get second identical layer in second dataframe and do selection l2 = arcpy.mapping.ListLayers(mxd,layername,df2)[0] sQuery = '"FID" IN (' + toselect + ')' arcpy.SelectLayerByAttribute_management(l2,"NEW_SELECTION",sQuery)


Duncan
0 Kudos