<?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: Calling a custom script tool within a loop in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662785#M51498</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your ideas.:D&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using arcpy.ImportTool(path_to_the_toolbox) to add the toolbox I need. I've imported at the beginning of the loop but I've tried several places and the problem persist.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;About the messages I have the same problem, none of the them return to the loop script:(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Esther&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 12 Mar 2011 06:41:40 GMT</pubDate>
    <dc:creator>EstherFernández_García</dc:creator>
    <dc:date>2011-03-12T06:41:40Z</dc:date>
    <item>
      <title>Calling a custom script tool within a loop</title>
      <link>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662782#M51495</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi everybody!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm having an issue calling a custom tool (python code) from another script tool. I need to loop through a bunch of folders and execute the custom tool for each one of them. If I call a model tool (from the same toolbox) inside the loop everything works fine but If I call the custom script tool it seems arcpy is not able to find the tool. The script tool calls to other custom modules.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.AttributeError'&amp;gt;: Object: Tool or environment &amp;lt;s&amp;gt; not found&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I try a second execution the error is slightly different:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.AttributeError'&amp;gt;: 'NoneType' object has no attribute 'LectorASC_AdmLocal'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;'AdmLocal' is the alias of my toolbox and 'LectorASC' the name of my python tool. This is the call I'm doing inside the loop:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.LectorASC_AdmLocal(DXFPolyline,subpar)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The weird thing is the first call in the loop works fine but the second throw the exception.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advanced&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Esther&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Mar 2011 19:04:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662782#M51495</guid>
      <dc:creator>EstherFernández_García</dc:creator>
      <dc:date>2011-03-10T19:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a custom script tool within a loop</title>
      <link>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662783#M51496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Esther,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This may not help in your situation, but I ran into a similar problem with 9.3.1. I finally added a few lines of code to to my 'looping script' to list all of the available tools (gp.ListTools and a 'for' loop to print the list).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the printed list of tools, I noticed that the tool that I was calling within the loop was listed 3 times This was because I had added it to a couple of other toolboxes. Once I removed the other instances of the script tool from ArcToolbox, the problem went away.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2011 23:46:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662783#M51496</guid>
      <dc:creator>StevePeaslee</dc:creator>
      <dc:date>2011-03-11T23:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a custom script tool within a loop</title>
      <link>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662784#M51497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Esther,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another thought. Are you using gp.AddToolbox inside your loop? That might cause problems.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One issue that I haven't figured out. Perhaps you can help me...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;None of my gp messages are printing from the second script that is called from the first script with the loop. Do you have that problem?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2011 23:50:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662784#M51497</guid>
      <dc:creator>StevePeaslee</dc:creator>
      <dc:date>2011-03-11T23:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a custom script tool within a loop</title>
      <link>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662785#M51498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your ideas.:D&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using arcpy.ImportTool(path_to_the_toolbox) to add the toolbox I need. I've imported at the beginning of the loop but I've tried several places and the problem persist.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;About the messages I have the same problem, none of the them return to the loop script:(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Esther&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 12 Mar 2011 06:41:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662785#M51498</guid>
      <dc:creator>EstherFernández_García</dc:creator>
      <dc:date>2011-03-12T06:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a custom script tool within a loop</title>
      <link>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662786#M51499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Experiencing the same problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using 9.3.1 and gp.AddToolbox&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any news on this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Sep 2011 16:38:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662786#M51499</guid>
      <dc:creator>MichaelFaulcon1</dc:creator>
      <dc:date>2011-09-22T16:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a custom script tool within a loop</title>
      <link>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662787#M51500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your problem may be different, but we worked out a solution for something similar &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/34790-Schedule-a-script-AttributeError-module-object-has-no-attribute"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Essentially, you are trying to import the tool by its name, however what a toolbox model is listed as in ArcCatalog/Map is actually just the &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;label &lt;/STRONG&gt;&lt;SPAN&gt;for the tool. You have to set the &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;name &lt;/STRONG&gt;&lt;SPAN&gt;by right clicking on it in Catalog, then under the General tab editing the Name field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When a toolbox is imported, its models are added to the arcpy namespace (stuff you can access with the line arcpy.something) by their &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;name&lt;/STRONG&gt;&lt;SPAN&gt; (not label) plus the toolbox alias you assign when importing it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you open your toolbox in Catalog and make sure the name is set correctly, not just the label, your model should run fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You also have (in this particular case, calling one Python code from another) the option to skip the Arc toolbox bits all together, which would probably increase reliability and speed, by calling the second Python directly script from the first. If you want more information on this let me know; I am planning on posting a tutorial on how to do this on my blog soon, but I'll try to get it done more quickly if there is a demand.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know how you get on!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Sep 2011 20:08:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662787#M51500</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2011-09-22T20:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a custom script tool within a loop</title>
      <link>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662788#M51501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;All tools in toolbox run fine the first time thru the loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is only on subsequent calls that I get an error "Tool or environment xxx not found"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Sep 2011 21:57:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662788#M51501</guid>
      <dc:creator>MichaelFaulcon1</dc:creator>
      <dc:date>2011-09-22T21:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a custom script tool within a loop</title>
      <link>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662789#M51502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You will have to post your code (or the most simplified version you can that still produces the error) before I can help more...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Sep 2011 23:30:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calling-a-custom-script-tool-within-a-loop/m-p/662789#M51502</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2011-09-22T23:30:33Z</dc:date>
    </item>
  </channel>
</rss>

