<?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 Re: List all layers in an arcmap session in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298501#M23110</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The problem I am having is that to test I set the env.workspace ="d:/myproj/mastergdb.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so it always looks in mastergdb.&amp;nbsp; What I need to find out is how to set the env.workspace to what "CURRENT" is looking at.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to display all of the feature classes in the current Arcmap session.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Jan 2012 15:44:12 GMT</pubDate>
    <dc:creator>WilliamIde</dc:creator>
    <dc:date>2012-01-25T15:44:12Z</dc:date>
    <item>
      <title>List all layers in an arcmap session</title>
      <link>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298497#M23106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would like to fill a listbox&amp;nbsp; with all of the FCs in a working Arcmap session.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I and do a list from a GDB like&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = "d:/foo/DefWrkCpc/Mystuff.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fc_list = arcpy.ListFeatureClasses()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for item in fc_list:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myLstBox(.insert(END,item)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can't seem to get &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;nlaylst = arcpy.mapping.ListLayers(mxd)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;nfc_list = []&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for layer in nlaylst:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nfc_list += arcpy.ListFeatureClasses(layer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To work&amp;nbsp; any ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jan 2012 20:31:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298497#M23106</guid>
      <dc:creator>WilliamIde</dc:creator>
      <dc:date>2012-01-24T20:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: List all layers in an arcmap session</title>
      <link>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298498#M23107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I know what you are asking for given your question but your code really doesn't make sense.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe try &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;nfc_list.append(layer)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe if you commented exactly what each part is suppoosed to be doing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example I am not sure why you are trying to get a list of feature classes from layers.&amp;nbsp; I don't think 'layer' is an appropriate argument for arcpy.ListFeatureClasses()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could also try &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fcList = arcpy.listFeatureClasses()

for fc in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; nfc_list.append(fc)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:20:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298498#M23107</guid>
      <dc:creator>HenryColgate</dc:creator>
      <dc:date>2021-12-11T14:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: List all layers in an arcmap session</title>
      <link>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298499#M23108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;env.workspace = "d:/foo/DefWrkCpc/Mystuff.gdb"&amp;nbsp; # Set environment&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fc_list = arcpy.ListFeatureClasses()&amp;nbsp; #&amp;nbsp; Get FeatureClass list from&amp;nbsp; a given gdb. This works except I forget the strip&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fc_list = [field.rstrip() for field in fc_list]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# This loads the list into a LB This works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for item in fc_list:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;myLstBox(.insert(END,item)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# I can't seem to get the following code to work.&amp;nbsp; I will try the append.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# This &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;nlaylst = arcpy.mapping.ListLayers(mxd)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;nfc_list = []&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for layer in nlaylst:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;nfc_list += arcpy.ListFeatureClasses(layer)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jan 2012 14:05:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298499#M23108</guid>
      <dc:creator>WilliamIde</dc:creator>
      <dc:date>2012-01-25T14:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: List all layers in an arcmap session</title>
      <link>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298500#M23109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;nfc_list.append(layer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;which seems to be that same as the += assignment.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is I was setting input parameters in properties of add script.&amp;nbsp; I changed it and it works.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jan 2012 15:10:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298500#M23109</guid>
      <dc:creator>WilliamIde</dc:creator>
      <dc:date>2012-01-25T15:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: List all layers in an arcmap session</title>
      <link>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298501#M23110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The problem I am having is that to test I set the env.workspace ="d:/myproj/mastergdb.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so it always looks in mastergdb.&amp;nbsp; What I need to find out is how to set the env.workspace to what "CURRENT" is looking at.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to display all of the feature classes in the current Arcmap session.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jan 2012 15:44:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298501#M23110</guid>
      <dc:creator>WilliamIde</dc:creator>
      <dc:date>2012-01-25T15:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: List all layers in an arcmap session</title>
      <link>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298502#M23111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;if you're trying to list the layers inside of your current mxd's map document then you don't want to be using the gdb at all. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this worked for me in an arcmap session:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
mxdlyrs = arcpy.mapping.ListLayers(mxd, "*")

for lyr in mxdlyrs: 
&amp;nbsp;&amp;nbsp; print lyr&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I would like to fill a listbox&amp;nbsp; with all of the FCs in a working Arcmap session.&lt;BR /&gt;&lt;BR /&gt;I and do a list from a GDB like&lt;BR /&gt;&lt;BR /&gt;env.workspace = "d:/foo/DefWrkCpc/Mystuff.gdb"&lt;BR /&gt;&lt;BR /&gt;fc_list = arcpy.ListFeatureClasses()&lt;BR /&gt;&lt;BR /&gt;for item in fc_list:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myLstBox(.insert(END,item)&lt;BR /&gt;&lt;BR /&gt;I can't seem to get &lt;BR /&gt;&lt;BR /&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;BR /&gt;&lt;BR /&gt;nlaylst = arcpy.mapping.ListLayers(mxd)&lt;BR /&gt;&lt;BR /&gt;nfc_list = []&lt;BR /&gt;for layer in nlaylst:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nfc_list += arcpy.ListFeatureClasses(layer)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To work&amp;nbsp; any ideas?&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:20:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298502#M23111</guid>
      <dc:creator>JoshuaChan</dc:creator>
      <dc:date>2021-12-11T14:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: List all layers in an arcmap session</title>
      <link>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298503#M23112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The existing geoprocessing framework has facilities for this sort of thing without custom GUIs or code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Simply create a script tool and set one of the input parameters to be of type Feature Layer and that parameter will become a listbox on the tool dialog with a list of all the feature layers in the current ArcMap document as well as temporary feature layers that have been created during the current session through other means such as Make Feature Layer. This works similarly with Table Views and possibly other parameter types.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would strongly recommend taking advantage the geoprocessing framework where possible instead of reinventing the wheel.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jan 2012 17:05:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298503#M23112</guid>
      <dc:creator>LoganPugh</dc:creator>
      <dc:date>2012-01-25T17:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: List all layers in an arcmap session</title>
      <link>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298504#M23113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That got it thank you sir.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Logan Yea I know, this is only a small part of a bigger script that I need to put together.&amp;nbsp; I almost always stay in the framework except when I don't.:)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jan 2012 17:30:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-layers-in-an-arcmap-session/m-p/298504#M23113</guid>
      <dc:creator>WilliamIde</dc:creator>
      <dc:date>2012-01-25T17:30:22Z</dc:date>
    </item>
  </channel>
</rss>

