<?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 List Layers in Data Frame Extent in Python Add-in in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/list-layers-in-data-frame-extent-in-python-add-in/m-p/531262#M41607</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This has been a project that I want to test out but, due to my lack of the Python language, it's been very difficult for me to construct the layout of the code.&amp;nbsp; It has many steps but the first one is hard for me to understand what commands I should be using.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to make a python add-in that looks at polygons that are in the data frame extent and populates a drop down menu with them (using one of its field columns to populate the list).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This might be the first of many questions but any help would be great!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 29 Apr 2020 21:00:34 GMT</pubDate>
    <dc:creator>EvanMyers1</dc:creator>
    <dc:date>2020-04-29T21:00:34Z</dc:date>
    <item>
      <title>List Layers in Data Frame Extent in Python Add-in</title>
      <link>https://community.esri.com/t5/python-questions/list-layers-in-data-frame-extent-in-python-add-in/m-p/531262#M41607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This has been a project that I want to test out but, due to my lack of the Python language, it's been very difficult for me to construct the layout of the code.&amp;nbsp; It has many steps but the first one is hard for me to understand what commands I should be using.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to make a python add-in that looks at polygons that are in the data frame extent and populates a drop down menu with them (using one of its field columns to populate the list).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This might be the first of many questions but any help would be great!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Apr 2020 21:00:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-layers-in-data-frame-extent-in-python-add-in/m-p/531262#M41607</guid>
      <dc:creator>EvanMyers1</dc:creator>
      <dc:date>2020-04-29T21:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: List Layers in Data Frame Extent in Python Add-in</title>
      <link>https://community.esri.com/t5/python-questions/list-layers-in-data-frame-extent-in-python-add-in/m-p/531263#M41608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When creating a new script tool or add-in, I will start experimenting in the Python window with the various arcpy functions that look applicable.&amp;nbsp; From your description, you are wanting something to identify polygon layers, select one of those layers, make an initial selection of polygons from the current map extent, and get a list of attributes to allow the user to make a further choices.&amp;nbsp; I hope this is a reasonable summary of your project.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With that in mind, here's a test script that I've been experimenting with in the Python window using desktop 10.5.&amp;nbsp; You may need to check the arcpy functions if you're using Pro or other version.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;mxd &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MapDocument&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
polyLayers &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# empty list&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# ListLayers (map_document_or_layer, {wildcard}, {data_frame})&lt;/SPAN&gt;
lyrs &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;mxd&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; lyrs&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="comment token"&gt;# Describe (object)&lt;/SPAN&gt;
    desc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Describe&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; desc&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ShapeType &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Polygon'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        polyLayers&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

selected_layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; polyLayers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# for demo, select first layer&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; selected_layer

fields &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# empty list for field selection&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# ListFields (dataset, {wild_card}, {field_type})&lt;/SPAN&gt;
flds &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListFields&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;selected_layer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field_type&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'String'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; f &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; flds&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="comment token"&gt;# print f.name&lt;/SPAN&gt;
    fields&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; fields
selected_field &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; fields&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# select first field tor testing&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; selected_field

&lt;SPAN class="comment token"&gt;# get extent and select polygons in selected layer&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# ListDataFrames (map_document, {wildcard})&lt;/SPAN&gt;
df &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListDataFrames&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;mxd&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"*"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
ext &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; df&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;extent
array &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Array&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Point&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ext&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;XMin&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; ext&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;YMin&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
                     arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Point&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ext&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;XMin&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; ext&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;YMax&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
                     arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Point&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ext&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;XMax&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; ext&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;YMax&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
                     arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Point&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ext&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;XMax&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; ext&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;YMin&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
                     &lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
polygon &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Polygon&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;array&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# use this polygon for making selection&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# SelectLayerByLocation_management (in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type}, {invert_spatial_relationship})&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByLocation_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;selected_layer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"INTERSECT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; polygon&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"NEW_SELECTION"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"NOT_INVERT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

selected &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# empty list for selected polygons' attributes&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# SearchCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause})&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;selected_layer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;selected_field&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        selected&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; selected &lt;SPAN class="comment token"&gt;# user would choose from this list&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# SelectLayerByAttribute(in_layer_or_view, {selection_type}, {where_clause}, {invert_where_clause})&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByAttribute_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;selected_layer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"CLEAR_SELECTION"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# clear selected items&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍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‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Once the code is tested and does what is desired, then you can work it into a script tool or add-in.&amp;nbsp; Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:07:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-layers-in-data-frame-extent-in-python-add-in/m-p/531263#M41608</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-11T23:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: List Layers in Data Frame Extent in Python Add-in</title>
      <link>https://community.esri.com/t5/python-questions/list-layers-in-data-frame-extent-in-python-add-in/m-p/1012638#M59392</link>
      <description>&lt;P&gt;good idea, there's a simple method to get polygon from extent after v10.3:&lt;/P&gt;&lt;P&gt;polygon=df.extent.polygon&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2020 13:26:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-layers-in-data-frame-extent-in-python-add-in/m-p/1012638#M59392</guid>
      <dc:creator>pyfans</dc:creator>
      <dc:date>2020-12-29T13:26:17Z</dc:date>
    </item>
  </channel>
</rss>

