Skip to main content
deleted 81 characters in body
Source Link
Mark Bryant
  • 1.4k
  • 8
  • 7

You can also just do it with a few lines of code. This has the advantage over the make layer from selected feature, in that you can see the query definition.

def qdef_selected_features(lyr): desc = arcpy.Describe(lyr) # Get a semicolon-delimited string of selected feature IDs fid_list = desc.FIDSet.split(";") # build the query definition query = '{} IN ({})'.format(desc.OIDFieldName, ",".join(fid_list)) # apply the query definition, creatingback ato newthe layer # This is not persisted and must be saved arcpy.management.MakeFeatureLayer(lyr,'outLayer',.definitionQuery = query) 

You can also just do it with a few lines of code. This has the advantage over the make layer from selected feature, in that you can see the query definition.

def qdef_selected_features(lyr): desc = arcpy.Describe(lyr) # Get a semicolon-delimited string of selected feature IDs fid_list = desc.FIDSet.split(";") # build the query definition query = '{} IN ({})'.format(desc.OIDFieldName, ",".join(fid_list)) # apply the query definition, creating a new layer # This is not persisted and must be saved arcpy.management.MakeFeatureLayer(lyr,'outLayer', query) 

You can also just do it with a few lines of code. This has the advantage over the make layer from selected feature, in that you can see the query definition.

def qdef_selected_features(lyr): desc = arcpy.Describe(lyr) # Get a semicolon-delimited string of selected feature IDs fid_list = desc.FIDSet.split(";") # build the query definition query = '{} IN ({})'.format(desc.OIDFieldName, ",".join(fid_list)) # apply the query definition back to the layer lyr.definitionQuery = query 
Source Link
Mark Bryant
  • 1.4k
  • 8
  • 7

You can also just do it with a few lines of code. This has the advantage over the make layer from selected feature, in that you can see the query definition.

def qdef_selected_features(lyr): desc = arcpy.Describe(lyr) # Get a semicolon-delimited string of selected feature IDs fid_list = desc.FIDSet.split(";") # build the query definition query = '{} IN ({})'.format(desc.OIDFieldName, ",".join(fid_list)) # apply the query definition, creating a new layer # This is not persisted and must be saved arcpy.management.MakeFeatureLayer(lyr,'outLayer', query)