There are several variations on this out there but all are use the OID/FID of the FC to create the query. I'd like to modify this to accommodate a different field which is still an integer value.
The thing is arcpy.Describe makes it damn easy to get a list of FIDs. Am I missing something here or am I going to have to build a list by other means?
I do realize you could use a loop to create a super long query using 'OR' but given that the attribute values are integer, I see no reason to use 'IN' for this.
Here's some code:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token">#Assumes the layer in ArcMap has a selected features</SPAN>
lyr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>Layer<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"yourLayer"</SPAN><SPAN class="punctuation token">)</SPAN>
lyrDesc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">)</SPAN>
fieldDesc <SPAN class="operator token">=</SPAN> lyrDesc<SPAN class="punctuation token">.</SPAN>FIDset
selectedList <SPAN class="operator token">=</SPAN> fieldDesc<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">";"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Build your query; the below is poor since it assumes "OBJECTID" is present; this is a draft</SPAN>
sql <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{} IN ({})"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"OBJECTID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">", "</SPAN><SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>str<SPAN class="punctuation token">(</SPAN>n<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> n <SPAN class="keyword token">in</SPAN> selectedList<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Apply the definition query</SPAN>
lyr<SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> sql<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>