<?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: run python script from custom toolbox in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/run-python-script-from-custom-toolbox/m-p/226927#M17580</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;nevermind this thread and sorry for the trouble. The script runs fine, I had forgot to add the .py extension to my script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Bogdan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 20 Jun 2011 15:07:01 GMT</pubDate>
    <dc:creator>bogdanpalade1</dc:creator>
    <dc:date>2011-06-20T15:07:01Z</dc:date>
    <item>
      <title>run python script from custom toolbox</title>
      <link>https://community.esri.com/t5/python-questions/run-python-script-from-custom-toolbox/m-p/226926#M17579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to add a script to a toolbox in order to run it more confortably. The script will repair data sources (for data moved from &lt;/SPAN&gt;&lt;STRONG&gt;initialFolder&lt;/STRONG&gt;&lt;SPAN&gt; to &lt;/SPAN&gt;&lt;STRONG&gt;finalFolder&lt;/STRONG&gt;&lt;SPAN&gt;) within several mxd files (present in &lt;/SPAN&gt;&lt;STRONG&gt;folderPath&lt;/STRONG&gt;&lt;SPAN&gt;) and is mainly a copy from the ArcGis help file. I will list it here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os

folderPath = arcpy.GetParametersAsText(0)
initialFolder = arcpy.GetParametersAsText(1)
finalFolder = arcpy.GetParametersAsText(2)
for filename in os.listdir(folderPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fullpath = os.path.join(folderPath, filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullpath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, extension = os.path.splitext(fullpath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extension.lower() == ".mxd":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullpath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(initialFolder, finalFolder)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()

del mxd
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that while it runs perfectly as python script with python idle, it would not run as a script in arcgis toolbox. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I added the script to a new toolbox and I defined the parameters as is follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;folderPath = folder type, input&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;initialFolder = folder type, input&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;finalFolder = folder type, input.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also tried replacing the folder type with workspace type but still does not work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;when I run the script I get the error: "Error in executing cmd.exe "path to the script. ...Failed to execute script".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you know what may be the problem?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Bogdan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Jun 2011 14:14:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/run-python-script-from-custom-toolbox/m-p/226926#M17579</guid>
      <dc:creator>bogdanpalade1</dc:creator>
      <dc:date>2011-06-20T14:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: run python script from custom toolbox</title>
      <link>https://community.esri.com/t5/python-questions/run-python-script-from-custom-toolbox/m-p/226927#M17580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;nevermind this thread and sorry for the trouble. The script runs fine, I had forgot to add the .py extension to my script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Bogdan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Jun 2011 15:07:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/run-python-script-from-custom-toolbox/m-p/226927#M17580</guid>
      <dc:creator>bogdanpalade1</dc:creator>
      <dc:date>2011-06-20T15:07:01Z</dc:date>
    </item>
  </channel>
</rss>

