<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Make feature layer from selected features in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/make-feature-layer-from-selected-features/m-p/1341725#M69034</link>
    <description>&lt;P&gt;I am trying to create a feature layer from the current selection. The selection can be one feature or multiple features. I have an ERROR 000358: Invalid expression on line 9. I am assuming my where clause is wrong?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;ptSelection = "points"
parcel = 'TaxParcels'
PF = "memory\PointFeat"


selected_features = arcpy.Describe(ptSelection).FIDSet

where_clause="OBJECTID = {}".format(selected_features)
arcpy.MakeFeatureLayer_management(ptSelection, PF, where_claus&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Oct 2023 22:28:12 GMT</pubDate>
    <dc:creator>CCWeedcontrol</dc:creator>
    <dc:date>2023-10-25T22:28:12Z</dc:date>
    <item>
      <title>Make feature layer from selected features</title>
      <link>https://community.esri.com/t5/python-questions/make-feature-layer-from-selected-features/m-p/1341725#M69034</link>
      <description>&lt;P&gt;I am trying to create a feature layer from the current selection. The selection can be one feature or multiple features. I have an ERROR 000358: Invalid expression on line 9. I am assuming my where clause is wrong?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;ptSelection = "points"
parcel = 'TaxParcels'
PF = "memory\PointFeat"


selected_features = arcpy.Describe(ptSelection).FIDSet

where_clause="OBJECTID = {}".format(selected_features)
arcpy.MakeFeatureLayer_management(ptSelection, PF, where_claus&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 22:28:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-feature-layer-from-selected-features/m-p/1341725#M69034</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-10-25T22:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Make feature layer from selected features</title>
      <link>https://community.esri.com/t5/python-questions/make-feature-layer-from-selected-features/m-p/1341755#M69036</link>
      <description>&lt;P&gt;Try using IN instead of = and see if that fixes it.&lt;/P&gt;&lt;P&gt;Also, not to be that guy, but line 9 is cut off.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 23:54:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-feature-layer-from-selected-features/m-p/1341755#M69036</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-10-25T23:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Make feature layer from selected features</title>
      <link>https://community.esri.com/t5/python-questions/make-feature-layer-from-selected-features/m-p/1342873#M69063</link>
      <description>&lt;P&gt;The format SQL expects for a list is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;&amp;lt;FIELD&amp;gt; IN (LIST,OF,VALUES)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;According to the Docs, FIDSet returns a string in the format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"LIST;OF;VALUES"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So to properly format that query, you'd need to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;selected_features = arcpy.Describe(selection).FIDSet

query_list = f"({','.join([val for val in selected_features.split(';')])})"

where_clause = f"OBJECTID IN {query_list}"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It also &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/tableview-properties.htm" target="_self"&gt;appears according to the docs&lt;/A&gt; that the TableView Describe object has a "whereClause" property that returns the exact query string used in the table view, so hypothetically you could just:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#...
where_clause = arcpy.Describe(selection).whereClause
arcpy.MakeFeatureLayer(ptSelection, PF, where_clause)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 18:28:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-feature-layer-from-selected-features/m-p/1342873#M69063</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2023-10-27T18:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Make feature layer from selected features</title>
      <link>https://community.esri.com/t5/python-questions/make-feature-layer-from-selected-features/m-p/1343990#M69085</link>
      <description>&lt;P&gt;Thank you, that worked&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 17:16:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-feature-layer-from-selected-features/m-p/1343990#M69085</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-10-31T17:16:36Z</dc:date>
    </item>
  </channel>
</rss>

