<?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: Setting scratchWorkspace and scratchGDB  in a Python Toolbox in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/setting-scratchworkspace-and-scratchgdb-nbsp-in-a/m-p/146654#M11444</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmm...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was previously establising the scratchWorkspace under the Execute defintion and I swear it was throwing syntax errors. Ok, chalk that one off to user error, I guess.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def execute(self, parameters, messages):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; """The tool logic to perform once the tool is executed."""
arcpy.env.workspace = "C:\Temp"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Works fine, except I&amp;nbsp; decided look at the Scratch Workspace in the tool GUI and the value is blank. Shouldn't the value "C:\Temp" be populated in the GUI?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In any case, I cant get scratchGDB to take without an error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
class Tool(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; """Define the tool's attributes."""
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.label = "MyTool"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.description = "Tool1"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.canRunInBackground = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.scratchGDB = r"C:\Temp\MyGDB.gdb"
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;When I do that, 'MyTool' throws an error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&amp;nbsp; File "&amp;lt;string&amp;gt;", line 31, in __init__&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 529, in set_&amp;nbsp;&amp;nbsp;&amp;nbsp; self[env] = val&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 581, in __setitem__&amp;nbsp;&amp;nbsp;&amp;nbsp; ret_ = setattr(self._gp, item, value)AttributeError: Object: Environment &amp;lt;scratchGDB&amp;gt; cannot be set&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It doesn't matter if I use scratchGDB at _init_, getParameterInfo, or execute, result is always the same.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:00:01 GMT</pubDate>
    <dc:creator>JohnDye</dc:creator>
    <dc:date>2021-12-11T08:00:01Z</dc:date>
    <item>
      <title>Setting scratchWorkspace and scratchGDB  in a Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/setting-scratchworkspace-and-scratchgdb-nbsp-in-a/m-p/146652#M11442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I know that since Python Toolboxes are run in an application, they probably honor the executing application's environment settings. However, I also know if you explicitly establish an environment setting in a Python Script, such as env.scratchWorkspace, then the script is &lt;/SPAN&gt;&lt;SPAN style="font-style: italic; text-decoration: underline;"&gt;supposed&lt;/SPAN&gt;&lt;SPAN&gt; to override the application's environment setting.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to set a scratchWorkspace and scratchGDB in a Python toolbox tool to ensure that intermediate data locations are consistent no matter which system is executing the tool, but it keeps throwing a syntax error, even though the syntax is correct. If I type the the statement into the Python Window:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
from arcpy import env

env.
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;Then intellisense brings up the scratchWorkspace and scratchGDB functions just fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But if I do the same in a Python Toolbox, I get a syntax error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are workspaces not supported programmatically in a python toolbox? Do I really have to have my users go and set it through the GUI?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You know, I dont know much in this small, cruel world, but ESRI, that ain't right. That. Just. Ain't. Right.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Disclaimer: &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;It is highly possible that workspaces are programmatically supported in python toolboxes and I am just a bit of a moron.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 17:51:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-scratchworkspace-and-scratchgdb-nbsp-in-a/m-p/146652#M11442</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2013-05-23T17:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: Setting scratchWorkspace and scratchGDB  in a Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/setting-scratchworkspace-and-scratchgdb-nbsp-in-a/m-p/146653#M11443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmm, I just added arcpy.env.scratchWorkspace = r"C:\temp" to an existing PYT and I didn't get any syntax errors and it ran through successfully. Maybe you could post more code?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 19:23:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-scratchworkspace-and-scratchgdb-nbsp-in-a/m-p/146653#M11443</guid>
      <dc:creator>LucasDanzinger</dc:creator>
      <dc:date>2013-05-23T19:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Setting scratchWorkspace and scratchGDB  in a Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/setting-scratchworkspace-and-scratchgdb-nbsp-in-a/m-p/146654#M11444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmm...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was previously establising the scratchWorkspace under the Execute defintion and I swear it was throwing syntax errors. Ok, chalk that one off to user error, I guess.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def execute(self, parameters, messages):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; """The tool logic to perform once the tool is executed."""
arcpy.env.workspace = "C:\Temp"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Works fine, except I&amp;nbsp; decided look at the Scratch Workspace in the tool GUI and the value is blank. Shouldn't the value "C:\Temp" be populated in the GUI?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In any case, I cant get scratchGDB to take without an error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
class Tool(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; """Define the tool's attributes."""
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.label = "MyTool"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.description = "Tool1"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.canRunInBackground = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.scratchGDB = r"C:\Temp\MyGDB.gdb"
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;When I do that, 'MyTool' throws an error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&amp;nbsp; File "&amp;lt;string&amp;gt;", line 31, in __init__&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 529, in set_&amp;nbsp;&amp;nbsp;&amp;nbsp; self[env] = val&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 581, in __setitem__&amp;nbsp;&amp;nbsp;&amp;nbsp; ret_ = setattr(self._gp, item, value)AttributeError: Object: Environment &amp;lt;scratchGDB&amp;gt; cannot be set&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It doesn't matter if I use scratchGDB at _init_, getParameterInfo, or execute, result is always the same.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:00:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-scratchworkspace-and-scratchgdb-nbsp-in-a/m-p/146654#M11444</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2021-12-11T08:00:01Z</dc:date>
    </item>
  </channel>
</rss>

