<?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 Model exported to Python from WebScript in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511756#M40224</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;not sure how safe it is, I am protected internally so here is my php and Python examples from my blog. One uses exec() and the other is a python server that does the work. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you can reach the model from your server, you can leave it as a toolbox and use a python script to call the tool (sometimes the model doesnt run properly when exported. I put the code from ESRI on the bottom of the post.&lt;/P&gt;&lt;P&gt;&lt;A href="http://paulcrickard.wordpress.com/2012/11/12/calling-python-from-php-a-gis-example/" title="http://paulcrickard.wordpress.com/2012/11/12/calling-python-from-php-a-gis-example/"&gt;Calling Python From PHP: A GIS Example | Architecture and Planning&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="http://paulcrickard.wordpress.com/2012/11/08/shapefile-creator-website-using-cherrypy/" title="http://paulcrickard.wordpress.com/2012/11/08/shapefile-creator-website-using-cherrypy/"&gt;Shapefile Creator Website Using Cherrypy | Architecture and Planning&lt;/A&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="kn" style="color: #0000ff;"&gt;import&lt;/SPAN&gt; &lt;SPAN class="nn"&gt;arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="c" style="color: #008000;"&gt;# Import custom toolbox&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ImportToolbox&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515;"&gt;"c:/tools/My_Analysis_Tools.tbx"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="k" style="color: #0000ff;"&gt;try&lt;/SPAN&gt;&lt;SPAN class="p"&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="c" style="color: #008000;"&gt;# Run tool in the custom toolbox. The tool is identified by&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="c" style="color: #008000;"&gt;# the tool name and the toolbox alias.&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;GetPoints_myanalysis&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515;"&gt;"c:/data/forest.shp"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="k" style="color: #0000ff;"&gt;except&lt;/SPAN&gt; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ExecuteError&lt;/SPAN&gt;&lt;SPAN class="p"&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="k" style="color: #0000ff;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;GetMessages&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="mi" style="color: #666666;"&gt;2&lt;/SPAN&gt;&lt;SPAN class="p"&gt;))&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 Oct 2014 22:58:58 GMT</pubDate>
    <dc:creator>PaulCrickard1</dc:creator>
    <dc:date>2014-10-08T22:58:58Z</dc:date>
    <item>
      <title>Run Model exported to Python from WebScript</title>
      <link>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511751#M40219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a Model that I run once a month, per a request from our Police department, that queries and dumps a shapefile to a specific folder.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently, the officer calls in a ServiceTicket, tells me what month, and I run the model and close the ticket.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like to do is start to Automate this process.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the Python script (exported from the Model) in a web folder. I have converted the folder to an Application (with an Application pool).&lt;/P&gt;&lt;P&gt;I have an HTML form I threw together...&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="xml" name="code"&gt;&amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html&amp;gt; &amp;nbsp; &amp;lt;head&amp;gt; &amp;nbsp; &amp;lt;meta charset="UTF-8"&amp;gt; &amp;nbsp; &amp;lt;title&amp;gt;Crime Export Form&amp;lt;/title&amp;gt; &amp;nbsp; &amp;lt;/head&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;lt;body&amp;gt; &amp;nbsp; &amp;lt;form action="CrimeExports.py" method="POST"&amp;gt; &amp;nbsp; &amp;lt;input type="text" name="Start_Month" value="January"/&amp;gt; &amp;nbsp; &amp;lt;input type="text" name="Start_Year" value="2014" /&amp;gt; &amp;nbsp; &amp;lt;input type="text" name="End_Month" value="February" /&amp;gt; &amp;nbsp; &amp;lt;input type="text" name="End_Year" value="2014" /&amp;gt; &amp;nbsp; &amp;lt;input type="text" name="Folder_to_store_export" value="\\path\to\where\I\want\to\save" /&amp;gt; &amp;nbsp; &amp;lt;input type="submit" /&amp;gt; &amp;nbsp; &amp;lt;/form&amp;gt; &amp;nbsp; &amp;lt;/body&amp;gt;&amp;nbsp;&amp;nbsp; &amp;lt;/html&amp;gt; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It does absolutely nothing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Oct 2014 18:44:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511751#M40219</guid>
      <dc:creator>BrianO_keefe</dc:creator>
      <dc:date>2014-10-03T18:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Run Model exported to Python from WebScript</title>
      <link>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511752#M40220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I should add I have never run a Python script on a web-server. I have a PHP background, lots of Javascript, and HTML (of course). So I'm clueless on this end for Python-ating...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Oct 2014 18:45:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511752#M40220</guid>
      <dc:creator>BrianO_keefe</dc:creator>
      <dc:date>2014-10-03T18:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Run Model exported to Python from WebScript</title>
      <link>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511753#M40221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This approach will not work, unfortunately.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A key thing to know about running things from an HTML form is that (for obvious reasons) web browsers can't normally access your file system. If they could, it would be very easy for people to inject malicious code into your http server to run on your machine and do all kinds of things you do not want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The best way to make a model run on a server is to share as a geoprocessing service from ArcGIS Desktop, using ArcGIS Server or ArcGIS Online.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if you want to automate this at all, you can write a little Python script to run a model without conversion. This way your model can have things like iterators that do not export... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14124024125726575" jivemacro_uid="_14124024125726575" modifiedtitle="true"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;arcpy.ImportToolbox("path to model", "tb")&lt;/P&gt;
&lt;P&gt;arcpy.tb.MyModelTool(arg1, arg2, arg3)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At any rate, I'd test from a command line first so at least you know that is working.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Oct 2014 05:56:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511753#M40221</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-10-04T05:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: Run Model exported to Python from WebScript</title>
      <link>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511754#M40222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the input Curtis!&lt;/P&gt;&lt;P&gt;The problem is my model has a set of parameters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an Internal and an External ArcGIS Web Server, using a Web Adaptor for External maps. Surely there is someway to get this Python script running on the Internal server?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Oct 2014 17:57:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511754#M40222</guid>
      <dc:creator>BrianO_keefe</dc:creator>
      <dc:date>2014-10-07T17:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Run Model exported to Python from WebScript</title>
      <link>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511755#M40223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; background-color: #f3f3f3;"&gt;The problem is my model has a set of parameters.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your model has parameters, you can pass them through python as follows&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14128028853867327 jive_text_macro" jivemacro_uid="_14128028853867327"&gt;
&lt;P&gt;import arcpy &lt;/P&gt;
&lt;P&gt;arg1 = arcpy.GetParameterAsText(0)&lt;/P&gt;
&lt;P&gt;arg2 = arcpy.GetParameterAsText(0)&lt;/P&gt;
&lt;P&gt;arg3 = arcpy.GetParameterAsText(0)&lt;/P&gt;
&lt;P&gt;arcpy.ImportToolbox("path to model", "tb") &lt;/P&gt;
&lt;P&gt;arcpy.tb.MyModelTool(arg1, arg2, arg3) &lt;/P&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From the OS you'd run it like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;C:\Python27\ArcGIS10.2\python.exe arg1 arg2 arg3&lt;/CODE&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 21:14:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511755#M40223</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-10-08T21:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Run Model exported to Python from WebScript</title>
      <link>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511756#M40224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;not sure how safe it is, I am protected internally so here is my php and Python examples from my blog. One uses exec() and the other is a python server that does the work. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you can reach the model from your server, you can leave it as a toolbox and use a python script to call the tool (sometimes the model doesnt run properly when exported. I put the code from ESRI on the bottom of the post.&lt;/P&gt;&lt;P&gt;&lt;A href="http://paulcrickard.wordpress.com/2012/11/12/calling-python-from-php-a-gis-example/" title="http://paulcrickard.wordpress.com/2012/11/12/calling-python-from-php-a-gis-example/"&gt;Calling Python From PHP: A GIS Example | Architecture and Planning&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="http://paulcrickard.wordpress.com/2012/11/08/shapefile-creator-website-using-cherrypy/" title="http://paulcrickard.wordpress.com/2012/11/08/shapefile-creator-website-using-cherrypy/"&gt;Shapefile Creator Website Using Cherrypy | Architecture and Planning&lt;/A&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="kn" style="color: #0000ff;"&gt;import&lt;/SPAN&gt; &lt;SPAN class="nn"&gt;arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="c" style="color: #008000;"&gt;# Import custom toolbox&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ImportToolbox&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515;"&gt;"c:/tools/My_Analysis_Tools.tbx"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="k" style="color: #0000ff;"&gt;try&lt;/SPAN&gt;&lt;SPAN class="p"&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="c" style="color: #008000;"&gt;# Run tool in the custom toolbox. The tool is identified by&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="c" style="color: #008000;"&gt;# the tool name and the toolbox alias.&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;GetPoints_myanalysis&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515;"&gt;"c:/data/forest.shp"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="k" style="color: #0000ff;"&gt;except&lt;/SPAN&gt; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ExecuteError&lt;/SPAN&gt;&lt;SPAN class="p"&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="k" style="color: #0000ff;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;GetMessages&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="mi" style="color: #666666;"&gt;2&lt;/SPAN&gt;&lt;SPAN class="p"&gt;))&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 22:58:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/run-model-exported-to-python-from-webscript/m-p/511756#M40224</guid>
      <dc:creator>PaulCrickard1</dc:creator>
      <dc:date>2014-10-08T22:58:58Z</dc:date>
    </item>
  </channel>
</rss>

