<?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 Auto populate script tool parameter with layers in a map document in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/auto-populate-script-tool-parameter-with-layers-in/m-p/4884#M423</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Does any one know how to auto populate a script tool parameter with list of layers in a map document when the map document is provided as the first parameter. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This functionality is common when opening arctoolbox tools within a map document. The input dataset parameters automatically pick up the layers and tables in the table of contents.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know that tool validation can be used to get the list of fields in a feature class. I did not have luck applying the same logic for list of layers in an mxd.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Oct 2013 15:19:43 GMT</pubDate>
    <dc:creator>RoySP</dc:creator>
    <dc:date>2013-10-03T15:19:43Z</dc:date>
    <item>
      <title>Auto populate script tool parameter with layers in a map document</title>
      <link>https://community.esri.com/t5/python-questions/auto-populate-script-tool-parameter-with-layers-in/m-p/4884#M423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Does any one know how to auto populate a script tool parameter with list of layers in a map document when the map document is provided as the first parameter. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This functionality is common when opening arctoolbox tools within a map document. The input dataset parameters automatically pick up the layers and tables in the table of contents.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know that tool validation can be used to get the list of fields in a feature class. I did not have luck applying the same logic for list of layers in an mxd.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Oct 2013 15:19:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/auto-populate-script-tool-parameter-with-layers-in/m-p/4884#M423</guid>
      <dc:creator>RoySP</dc:creator>
      <dc:date>2013-10-03T15:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Auto populate script tool parameter with layers in a map document</title>
      <link>https://community.esri.com/t5/python-questions/auto-populate-script-tool-parameter-with-layers-in/m-p/4885#M424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You'll want to work with validation scripts.&amp;nbsp; You get to validation scripts by right-clicking on a script tool, go to properties, and selecting the validation tab.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a sample script that updates a parameter with layer names once a map document &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; def updateParameters(self): &amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the values and properties of parameters before internal &amp;nbsp;&amp;nbsp;&amp;nbsp; validation is performed.&amp;nbsp; This method is called whenever a parmater &amp;nbsp;&amp;nbsp;&amp;nbsp; has been changed.""" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy &amp;nbsp;&amp;nbsp;&amp;nbsp; if self.params[0].value: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(self.params[0].value.value) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrs = arcpy.mapping.ListLayers(mxd) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerList = [] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in lyrs: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerList.append(lyr.name)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueList = list(set(layerList)) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueList.sort() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not self.params[1].altered: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[1].filter.list = uniqueList &amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is an arcpy.mapping sample scripts download that has about 20 different script tools and several different validation scripts.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://www.arcgis.com/home/item.html?id=18c19ec00acb4d568c27bc20a72bfdc8" rel="nofollow" target="_blank"&gt;http://www.arcgis.com/home/item.html?id=18c19ec00acb4d568c27bc20a72bfdc8&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The sample above is from the Replace Layer with Layer File example.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 14:34:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/auto-populate-script-tool-parameter-with-layers-in/m-p/4885#M424</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2013-10-04T14:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Auto populate script tool parameter with layers in a map document</title>
      <link>https://community.esri.com/t5/python-questions/auto-populate-script-tool-parameter-with-layers-in/m-p/4886#M425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is great! Thanks Jeff!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 17:14:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/auto-populate-script-tool-parameter-with-layers-in/m-p/4886#M425</guid>
      <dc:creator>RoySP</dc:creator>
      <dc:date>2013-10-04T17:14:09Z</dc:date>
    </item>
  </channel>
</rss>

