<?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: Python Toolbox to create buffer layer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645370#M74655</link>
    <description>&lt;P&gt;My apologies. Below is the error message. I tried changing in_memory to memory and got this same error.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrandonPrice1_0-1756160012140.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/139300iD93B80EFA2CD0992/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BrandonPrice1_0-1756160012140.png" alt="BrandonPrice1_0-1756160012140.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Aug 2025 22:15:55 GMT</pubDate>
    <dc:creator>BrandonPrice1</dc:creator>
    <dc:date>2025-08-25T22:15:55Z</dc:date>
    <item>
      <title>Python Toolbox to create buffer layer</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645251#M74647</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Can somebody advise me on how to code this properly? The below script was attempted using google AI snippets to create an in memory buffer layer of 500 feet based on the feature currently selected in the map. It throws an error when trying to run it. Also, if there is any advice on creating an editable layer from all features that intersect the buffer. Eventually, I plan to publish everything as a GP service.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import arcpy.mp

class Toolbox:
    def __init__(self):
        self.label = "Custom Buffer Tools"
        self.alias = "CustomBuffer"
        self.tools = [BufferSelectedFeatures] # Add your tool class here


class BufferSelectedFeatures(object):
    def __init__(self):
        self.label = "Buffer Selected Features"
        self.description = "Creates a 500-foot buffer around selected features."
        self.canRunInBackground = False

    def getParameterInfo(self):
        param0 = arcpy.Parameter(
            displayName="Input Feature Layer",
            name="in_features",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input")

        param1 = arcpy.Parameter(
            displayName="Output Buffer Layer Name",
            name="out_buffer_name",
            datatype="GPString",
            parameterType="Required",
            direction="Input")
        param1.value = "Selected_Feature_Buffer" # Default name

        return [param0, param1]

    def execute(self, parameters, messages):
        in_features = parameters[0].valueAsText
        out_buffer_name = parameters[1].valueAsText

        # Set the scratch workspace for temporary data
        arcpy.env.scratchWorkspace = "in_memory" 

        # Create the full path for the output buffer feature class
        out_buffer_fc = arcpy.ValidateTableName(out_buffer_name, arcpy.env.scratchWorkspace)

        # Buffer the selected features
        arcpy.Buffer_analysis(in_features, out_buffer_fc, "500 Feet")
        messages.addMessage(f"Buffer created: {out_buffer_fc}")

        # Add the buffer layer to the map (for ArcGIS Pro)
        aprx = arcpy.mp.ArcGISProject("CURRENT")
        active_map = aprx.activeMap
        
        # Make a feature layer from the buffered output
        arcpy.management.MakeFeatureLayer(out_buffer_fc, out_buffer_name)

        new_layer = arcpy.mp.Layer(out_buffer_name) # Create a Layer object from the temporary layer
        
        # Add the layer to the active map
        active_map.addLayer(new_layer)
        messages.addMessage(f"Buffer layer '{out_buffer_name}' added to the map.")

        return&lt;/LI-CODE&gt;&lt;P&gt;-Brandon&lt;/P&gt;</description>
      <pubDate>Mon, 25 Aug 2025 17:12:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645251#M74647</guid>
      <dc:creator>BrandonPrice1</dc:creator>
      <dc:date>2025-08-25T17:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox to create buffer layer</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645256#M74648</link>
      <description>&lt;P&gt;and what would the error be?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Aug 2025 17:20:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645256#M74648</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-08-25T17:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox to create buffer layer</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645288#M74649</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/358954"&gt;@BrandonPrice1&lt;/a&gt;,&lt;BR /&gt;&lt;STRONG&gt;&lt;BR /&gt;in-memory&lt;/STRONG&gt;&amp;nbsp;is legacy workspace.&amp;nbsp; You might try &lt;STRONG&gt;memory&lt;/STRONG&gt; depending on your ArcGIS version.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;See memory docs here: &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/basics/the-in-memory-workspace.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/basics/the-in-memory-workspace.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Tyler&lt;/P&gt;</description>
      <pubDate>Mon, 25 Aug 2025 18:37:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645288#M74649</guid>
      <dc:creator>TylerT</dc:creator>
      <dc:date>2025-08-25T18:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox to create buffer layer</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645370#M74655</link>
      <description>&lt;P&gt;My apologies. Below is the error message. I tried changing in_memory to memory and got this same error.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrandonPrice1_0-1756160012140.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/139300iD93B80EFA2CD0992/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BrandonPrice1_0-1756160012140.png" alt="BrandonPrice1_0-1756160012140.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Aug 2025 22:15:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645370#M74655</guid>
      <dc:creator>BrandonPrice1</dc:creator>
      <dc:date>2025-08-25T22:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox to create buffer layer</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645538#M74657</link>
      <description>&lt;P&gt;mp.Layer is a class that you can't initialize. It's a representation of a program object. You can use it to type hint a return value, but if you want to create a layer, you need to use MakeFeatureLayer and assign the result to a variable.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

class Toolbox:
    def __init__(self):
        self.label = "Custom Buffer Tools"
        self.alias = "CustomBuffer"
        self.tools = [BufferSelectedFeatures]


class BufferSelectedFeatures(object):
    def __init__(self):
        self.label = "Buffer Selected Features"
        self.description = "Creates a 500-foot buffer around selected features."
        self.canRunInBackground = False

    def getParameterInfo(self):
        in_features = arcpy.Parameter(
            name="in_features",
            displayName="Input Feature Layer",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input")

        out_buffer_name = arcpy.Parameter(
            name="out_buffer_name",
            displayName="Output Buffer Layer Name",
            datatype="GPString",
            parameterType="Required",
            direction="Input")
        out_buffer_name.value = "Selected_Feature_Buffer" # Default name

        return [in_features, out_buffer_name]

    def execute(self, parameters: list[arcpy.Parameter], messages):
        params = {p.name: p for p in parameters}
        in_features = params['in_features'].value
        out_buffer_name = params['out_buffer_name'].value
        aprx = arcpy.mp.ArcGISProject("CURRENT")
        
        with arcpy.EnvManager(workspace='memory'):
            # Create the full path for the output buffer feature class
            out_buffer_fc = arcpy.ValidateTableName(out_buffer_name)

            # Buffer the selected features
            arcpy.analysis.Buffer(in_features, out_buffer_fc, "500 Feet")
            
            # Make a feature layer from the buffered output
            new_layer = arcpy.management.MakeFeatureLayer(out_buffer_fc, out_buffer_name)[0]
            arcpy.AddMessage(f"Buffer created: {out_buffer_fc}")
        
        # Add the layer to the active map
        aprx.activeMap.addLayer(new_layer)
        arcpy.AddMessage(f"Buffer layer '{out_buffer_name}' added to the map.")&lt;/LI-CODE&gt;&lt;P&gt;Just a sidenote: with the workspace set to memory, the buffer layer will exist only in memory. You can accept a full derived layer path as a Parameter input if that's what you really want to do.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Aug 2025 12:25:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645538#M74657</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-08-26T12:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox to create buffer layer</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645924#M74663</link>
      <description>&lt;P&gt;Thanks. I appreciate it.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 01:32:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645924#M74663</guid>
      <dc:creator>BrandonPrice1</dc:creator>
      <dc:date>2025-08-27T01:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox to create buffer layer</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645931#M74664</link>
      <description>&lt;P&gt;Thanks again, this buffer tool intended to be used as a geoprocessing service. So, the newly generated buffer layer would be added to a webmap rather than a ArcGIS Pro Project. I will try using your sample and tweak it for online use.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 01:31:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-to-create-buffer-layer/m-p/1645931#M74664</guid>
      <dc:creator>BrandonPrice1</dc:creator>
      <dc:date>2025-08-27T01:31:01Z</dc:date>
    </item>
  </channel>
</rss>

