<?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 Setting Workspace in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/setting-workspace/m-p/484758#M37828</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'm a python and arcpy beginner. I have a few simple scripts I'm working on for practice, but I'm having trouble with this one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Purpose = Create a 200 ft buffer around a user selected feature. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Issue = I would like the 'output feature class' to default to a certain file path. I attempted to do this using &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;arcpy.env.workspace&lt;/SPAN&gt;&lt;SPAN&gt;. However, the default path keeps pointing to my C:\....Documents\ArcGIS\Default.gdb&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've looked at some other examples and cannot figure out what I am doing wrong. I'd appreciate any help. Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
from arcpy import env
import os

#----------------------------------
# Set the geoprocessing environment
#----------------------------------

env.workspace = r"J:\Work\Projects\Case Change Maps\Python\Temp"
env.overwriteOutput = True

#----------------------------------
# Get Parameters from the user
#----------------------------------

DataToBuffer = arcpy.GetParameterAsText(0)
if DataToBuffer == '#' or not DataToBuffer:
&amp;nbsp;&amp;nbsp;&amp;nbsp; DataToBuffer = "BASE.BASEMAP" # provide a default value if unspecified

BufferName = arcpy.GetParameterAsText(1)
if BufferName == '#' or not BufferName:
&amp;nbsp;&amp;nbsp;&amp;nbsp; BufferName = "BUFF.shp" # provide a default value if unspecified

#----------------------------------
# Process
#----------------------------------

# Buffer the basemap selection
arcpy.Buffer_analysis(DataToBuffer, BufferName, "200 Feet", "FULL", "ROUND", "NONE", "")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Aug 2011 17:32:20 GMT</pubDate>
    <dc:creator>AliciaSoto</dc:creator>
    <dc:date>2011-08-02T17:32:20Z</dc:date>
    <item>
      <title>Setting Workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-workspace/m-p/484758#M37828</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'm a python and arcpy beginner. I have a few simple scripts I'm working on for practice, but I'm having trouble with this one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Purpose = Create a 200 ft buffer around a user selected feature. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Issue = I would like the 'output feature class' to default to a certain file path. I attempted to do this using &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;arcpy.env.workspace&lt;/SPAN&gt;&lt;SPAN&gt;. However, the default path keeps pointing to my C:\....Documents\ArcGIS\Default.gdb&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've looked at some other examples and cannot figure out what I am doing wrong. I'd appreciate any help. Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
from arcpy import env
import os

#----------------------------------
# Set the geoprocessing environment
#----------------------------------

env.workspace = r"J:\Work\Projects\Case Change Maps\Python\Temp"
env.overwriteOutput = True

#----------------------------------
# Get Parameters from the user
#----------------------------------

DataToBuffer = arcpy.GetParameterAsText(0)
if DataToBuffer == '#' or not DataToBuffer:
&amp;nbsp;&amp;nbsp;&amp;nbsp; DataToBuffer = "BASE.BASEMAP" # provide a default value if unspecified

BufferName = arcpy.GetParameterAsText(1)
if BufferName == '#' or not BufferName:
&amp;nbsp;&amp;nbsp;&amp;nbsp; BufferName = "BUFF.shp" # provide a default value if unspecified

#----------------------------------
# Process
#----------------------------------

# Buffer the basemap selection
arcpy.Buffer_analysis(DataToBuffer, BufferName, "200 Feet", "FULL", "ROUND", "NONE", "")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2011 17:32:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-workspace/m-p/484758#M37828</guid>
      <dc:creator>AliciaSoto</dc:creator>
      <dc:date>2011-08-02T17:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-workspace/m-p/484759#M37829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think your safest bet would be to create an output folder location as another option for the script tool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;env.scratchWorkspace = arcpy.GetParameterAsText(2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then call it something like "Save To" and as a data type = Workspace.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If a person doesn't specify a location for their files to be dropped arcmap throws it in the default.gdb.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2011 17:54:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-workspace/m-p/484759#M37829</guid>
      <dc:creator>AndrewPerry</dc:creator>
      <dc:date>2011-08-02T17:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-workspace/m-p/484760#M37830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for the advice adperry. I went back and restructured my code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The script now works the way I had originally planned.The user selects a feature and a 200ft buffer shapefile is created and saved in a specific folder. The only question I have left now is how to get the resulting shapefile to appear in the TOC. I've tried using the &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;arcpy.mapping.AddLayer()&lt;/SPAN&gt;&lt;SPAN&gt; module, but I think I'm missing something.....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# ---------------------------------------------------------------------------
# Description:
#&amp;nbsp;&amp;nbsp; Creates a 200 ft buffer around a user selected feature
# ---------------------------------------------------------------------------

import arcpy
from arcpy import env
import os

#----------------------------------
# Set the geoprocessing environment
#----------------------------------

OutputBufferData = r"J:\Work\Projects\Case Change Maps\TempWorkspace\Buffer.shp"
env.overwriteOutput = True

#----------------------------------
# Get Parameters from the user
#----------------------------------

DataToBuffer = arcpy.GetParameterAsText(0)

#----------------------------------
# Processes
#----------------------------------

# Buffer the user selection
arcpy.Buffer_analysis(DataToBuffer, OutputBufferData, "200 Feet", "FULL", "ROUND", "NONE", "")

# Add results to the TOC
mxd = arcpy.mapping.MapDocument(r"J:\Work\Projects\Case Change Maps\Testing.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
addLayer = arcpy.mapping.Layer(OutputBufferData)
arcpy.mapping.AddLayer(df,addLayer,"TOP")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:22:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-workspace/m-p/484760#M37830</guid>
      <dc:creator>AliciaSoto</dc:creator>
      <dc:date>2021-12-11T21:22:15Z</dc:date>
    </item>
  </channel>
</rss>

