<?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: Issues bringing stand-alone python script in as a Script Tool in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/issues-bringing-stand-alone-python-script-in-as-a/m-p/192217#M14796</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure if what you put in there accurately reflects your code but:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Your projection file is probably missing a backslash? Should it be: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; spRef = r"E:\Code\WGS_1984_UTM_Zone_36N.prj"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- In the documentation for 'MakeXYEventLayer' it shows the spatial reference should be a spatial reference object. So maybe you need to create the spatial reference. spRef = arcpy.SpatialReference(r"E:\Code\WGS_1984_UTM_Zone_36N.prj")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- In the examples of SetNull, they have the word 'value' capitalized, ie. 'VALUE'. That could be causing a problem, see:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z00000007000000.htm"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z00000007000000.htm&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Sep 2012 21:50:25 GMT</pubDate>
    <dc:creator>GeorgeNewbury</dc:creator>
    <dc:date>2012-09-14T21:50:25Z</dc:date>
    <item>
      <title>Issues bringing stand-alone python script in as a Script Tool</title>
      <link>https://community.esri.com/t5/python-questions/issues-bringing-stand-alone-python-script-in-as-a/m-p/192216#M14795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to bring a script that runs perfectly well in command-line python into ArcMap as a Script Tool, and am having a couple of intransigent problems:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When run as a Script Tool, after the first run in the ArcMap session, there are often (but not always) errors regarding read-only status of data source etc, eg:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 484, in &amp;lt;lambda&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return lambda *args: val(*gp_fixargs(args, True))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: ERROR 999999: Error executing function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Workspace or data source is read only.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Workspace or data source is read only.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Workspace or data source is read only.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Workspace or data source is read only.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Workspace or data source is read only.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 010302: Unable to create the output raster: C:\Users\Dan Slayback\Documents\ArcGIS\Default.gdb\SetNull_Idw_1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 010067: Error in executing grid expression.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SetNull).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This never happens on the first run in the ArcMap session - sometimes you can run it twice, but rarely if ever 3 times. So I suspect it has to do with something being locked. I've tried lots of variations on deleting intermediate objects, but this has not consistently helped.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;More problematic is the fact that even when it runs without complaint as a Script Tool in ArcMap, the SetNull part is not working. Whereas, when run from a command prompt, it does. The guts of the code are as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy, string
&amp;nbsp;&amp;nbsp;&amp;nbsp; from arcpy.sa import Idw, RadiusFixed, SetNull

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.overwriteOutput = True

&amp;nbsp;&amp;nbsp;&amp;nbsp; spRef = r"E:Code\WGS_1984_UTM_Zone_36N.prj"
&amp;nbsp;&amp;nbsp;&amp;nbsp; pointlayer = "PointLayer"&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeXYEventLayer_management(csvfile, "X", "Y", pointlayer, spRef, 'Median')

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CheckOutExtension("Spatial")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Execute IDW
&amp;nbsp;&amp;nbsp;&amp;nbsp; searchRadius = RadiusFixed(1,"")
&amp;nbsp;&amp;nbsp;&amp;nbsp; outIDW = Idw("PointLayer", 'Median', 0.2, 2, searchRadius)

&amp;nbsp;&amp;nbsp; # Convert values &amp;lt; -1000 to NoData
&amp;nbsp;&amp;nbsp;&amp;nbsp; outSetNull = SetNull(outIDW, outIDW, "Value &amp;lt; -1000")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Save to tiff file
&amp;nbsp;&amp;nbsp;&amp;nbsp; outSetNull.save(outTiff)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Finally, this used to run both as a Script Tool (and from the dos prompt), without error, before I added the SetNull line, in an attempt to clean up some very low values that are coming out outside the perimeter of the data. (another problem - Idw does not seem to be doing the right thing here, but figured i could get around it with SetNull).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd greatly appreciate any suggestions on (1) what I should be deleting at the end of this in order to unlock any relevant files/workspaces for the next run, and whether to use 'del' or arcpy.Delete_management, and (2) why SetNull may not be working when run as a Script Tool.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Sep 2012 20:47:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issues-bringing-stand-alone-python-script-in-as-a/m-p/192216#M14795</guid>
      <dc:creator>DanSlayback</dc:creator>
      <dc:date>2012-09-06T20:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Issues bringing stand-alone python script in as a Script Tool</title>
      <link>https://community.esri.com/t5/python-questions/issues-bringing-stand-alone-python-script-in-as-a/m-p/192217#M14796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure if what you put in there accurately reflects your code but:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Your projection file is probably missing a backslash? Should it be: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; spRef = r"E:\Code\WGS_1984_UTM_Zone_36N.prj"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- In the documentation for 'MakeXYEventLayer' it shows the spatial reference should be a spatial reference object. So maybe you need to create the spatial reference. spRef = arcpy.SpatialReference(r"E:\Code\WGS_1984_UTM_Zone_36N.prj")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- In the examples of SetNull, they have the word 'value' capitalized, ie. 'VALUE'. That could be causing a problem, see:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z00000007000000.htm"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z00000007000000.htm&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Sep 2012 21:50:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issues-bringing-stand-alone-python-script-in-as-a/m-p/192217#M14796</guid>
      <dc:creator>GeorgeNewbury</dc:creator>
      <dc:date>2012-09-14T21:50:25Z</dc:date>
    </item>
  </channel>
</rss>

