<?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 Command work in Python Window but not in Python Toolbox in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/command-work-in-python-window-but-not-in-python/m-p/1240462#M66250</link>
    <description>&lt;P&gt;Just a simple command:&lt;/P&gt;&lt;PRE&gt;arcpy.analysis.Buffer('Target_Layer', 'C:/Buffer/Buffer.gdb/buffer', '100 Feet', 'FULL', 'ROUND', 'NONE')&lt;/PRE&gt;&lt;P&gt;It works in the Python Window, created a new layer in the gdb file.&amp;nbsp; However, when I change this to Python Tools:&lt;/P&gt;&lt;PRE&gt;def execute(self, params, messages):&lt;BR /&gt;    arcpy.analysis.Buffer('Target_Layer', 'C:/Buffer/Buffer.gdb/buffer', '100 Feet', 'FULL', 'ROUND', 'NONE')&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;It shows 'Tool completed', but nothing happen.&amp;nbsp; However, when I change the output to&amp;nbsp;'C:/Buffer/buffer' only, it can create a .shp file named 'buffer'.&amp;nbsp; What is the different between the script in Python Window and Python Toolbox.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Also, when I want to add the output layer in the gdb file to Contents, I type in the Python Window:&lt;/P&gt;&lt;PRE&gt;arcpy.management.MakeFeatureLayer('buffer', 'buffer_lyr')&lt;/PRE&gt;&lt;P&gt;It works.&amp;nbsp; However, when I put it into Python Toolbox:&lt;/P&gt;&lt;PRE&gt;def execute(self, params, messages):&lt;BR /&gt;    arcpy.management.MakeFeatureLayer('buffer', 'buffer_lyr')&lt;/PRE&gt;&lt;P&gt;It shows:&lt;/P&gt;&lt;PRE&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 80, in execute&lt;/PRE&gt;&lt;P&gt;I found some solution said that the layer in gdb need to change to .lyr file and then use the .addLayer() function.&amp;nbsp; Can I have a way need not to create a .lyr file just like I did in the Python Window.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Dec 2022 04:06:02 GMT</pubDate>
    <dc:creator>Leooo</dc:creator>
    <dc:date>2022-12-13T04:06:02Z</dc:date>
    <item>
      <title>Command work in Python Window but not in Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/command-work-in-python-window-but-not-in-python/m-p/1240462#M66250</link>
      <description>&lt;P&gt;Just a simple command:&lt;/P&gt;&lt;PRE&gt;arcpy.analysis.Buffer('Target_Layer', 'C:/Buffer/Buffer.gdb/buffer', '100 Feet', 'FULL', 'ROUND', 'NONE')&lt;/PRE&gt;&lt;P&gt;It works in the Python Window, created a new layer in the gdb file.&amp;nbsp; However, when I change this to Python Tools:&lt;/P&gt;&lt;PRE&gt;def execute(self, params, messages):&lt;BR /&gt;    arcpy.analysis.Buffer('Target_Layer', 'C:/Buffer/Buffer.gdb/buffer', '100 Feet', 'FULL', 'ROUND', 'NONE')&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;It shows 'Tool completed', but nothing happen.&amp;nbsp; However, when I change the output to&amp;nbsp;'C:/Buffer/buffer' only, it can create a .shp file named 'buffer'.&amp;nbsp; What is the different between the script in Python Window and Python Toolbox.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Also, when I want to add the output layer in the gdb file to Contents, I type in the Python Window:&lt;/P&gt;&lt;PRE&gt;arcpy.management.MakeFeatureLayer('buffer', 'buffer_lyr')&lt;/PRE&gt;&lt;P&gt;It works.&amp;nbsp; However, when I put it into Python Toolbox:&lt;/P&gt;&lt;PRE&gt;def execute(self, params, messages):&lt;BR /&gt;    arcpy.management.MakeFeatureLayer('buffer', 'buffer_lyr')&lt;/PRE&gt;&lt;P&gt;It shows:&lt;/P&gt;&lt;PRE&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 80, in execute&lt;/PRE&gt;&lt;P&gt;I found some solution said that the layer in gdb need to change to .lyr file and then use the .addLayer() function.&amp;nbsp; Can I have a way need not to create a .lyr file just like I did in the Python Window.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 04:06:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/command-work-in-python-window-but-not-in-python/m-p/1240462#M66250</guid>
      <dc:creator>Leooo</dc:creator>
      <dc:date>2022-12-13T04:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Command work in Python Window but not in Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/command-work-in-python-window-but-not-in-python/m-p/1240517#M66253</link>
      <description>&lt;P&gt;&lt;SPAN&gt;'C:/Buffer/buffer'&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;will assume you want to create the output in a folder since the workspace isn't a geodatabase like&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;'C:/Buffer/buffer.gdb'&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 10:28:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/command-work-in-python-window-but-not-in-python/m-p/1240517#M66253</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-12-13T10:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: Command work in Python Window but not in Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/command-work-in-python-window-but-not-in-python/m-p/1240971#M66265</link>
      <description>&lt;P&gt;I find the solution:&lt;/P&gt;&lt;P&gt;The new feature class is created and saved to the gdb file, but it is hidden in catalog and a refresh is needed to show it.&lt;/P&gt;&lt;P&gt;I can directly add the feature class to map, even it is hidden in the catalog.:&lt;/P&gt;&lt;PRE&gt;Buffer_lyr = '&lt;SPAN class=""&gt;C:/Buffer/Buffer.gdb/buffer"'&lt;/SPAN&gt;
aprx = arcpy.mp.ArcGISProject('&lt;SPAN class=""&gt;CURRENT'&lt;/SPAN&gt;)
aprxMap = aprx.listMaps()[&lt;SPAN class=""&gt;0&lt;/SPAN&gt;] 
aprxMap.addDataFromPath(Buffer_lyr)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 07:53:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/command-work-in-python-window-but-not-in-python/m-p/1240971#M66265</guid>
      <dc:creator>Leooo</dc:creator>
      <dc:date>2022-12-14T07:53:22Z</dc:date>
    </item>
  </channel>
</rss>

