<?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 using a python script to create a custom tool in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-a-python-script-to-create-a-custom-tool/m-p/39076#M3105</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My assignment is to create a custom tool on the tool bar using a python script. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All I want to do for now is add a previously created script, set the parameters, and get it to run. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Can I do this within ArcMap?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Where can I find a script to practice on? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 24 Mar 2013 19:38:43 GMT</pubDate>
    <dc:creator>DavidSchmidt2</dc:creator>
    <dc:date>2013-03-24T19:38:43Z</dc:date>
    <item>
      <title>using a python script to create a custom tool</title>
      <link>https://community.esri.com/t5/python-questions/using-a-python-script-to-create-a-custom-tool/m-p/39076#M3105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My assignment is to create a custom tool on the tool bar using a python script. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All I want to do for now is add a previously created script, set the parameters, and get it to run. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Can I do this within ArcMap?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Where can I find a script to practice on? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 Mar 2013 19:38:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-python-script-to-create-a-custom-tool/m-p/39076#M3105</guid>
      <dc:creator>DavidSchmidt2</dc:creator>
      <dc:date>2013-03-24T19:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: using a python script to create a custom tool</title>
      <link>https://community.esri.com/t5/python-questions/using-a-python-script-to-create-a-custom-tool/m-p/39077#M3106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Greetings, &lt;BR /&gt;&lt;BR /&gt;My assignment is to create a custom tool on the tool bar using a python script. &lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you need to create an add-in? Here's the help on that:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Help 10.1: Creating an AddIn project&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//014p00000022000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//014p00000022000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 Mar 2013 22:11:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-python-script-to-create-a-custom-tool/m-p/39077#M3106</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-03-24T22:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: using a python script to create a custom tool</title>
      <link>https://community.esri.com/t5/python-questions/using-a-python-script-to-create-a-custom-tool/m-p/39078#M3107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;probably the simplest thing to get you started is to just create a Python Addin with a single button on a toolbar that buffers a layer in the TOC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You'll need to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;&lt;A href="http://www.arcgis.com/home/item.html?id=5f3aefe77f6b4f61ad3e4c62f30bff3b" rel="nofollow noopener noreferrer" target="_blank"&gt;Download the Python Addin Wizard&lt;/A&gt;.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Start the Python Addin Wizard and Create a Toolbar with a Single Button on it.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Save the Addin and then hit the Open Folder Button.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Go into the Install Folder and script contained in that folder.&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;BR /&gt;&lt;SPAN&gt;For a button, you don't need any of the functions except for the OnClick function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
import pythonaddins

class SuperBuffer(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for LYR.THM_WkrsSqMi (Button)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.checked = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onClick(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Instantiate 'mxd' and 'df' as the Map Document and DataFrame variables
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("Current")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "'mxd' instantiated as Map Document variable."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "'df' instantiated as DataFrame variable."

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Create a Variable for the Layer you wish to Buffer. Later, you can get this dynamically
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #by using the 'arcpy.mapping.ListLayers' function to populate a Combobox with the layers
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #in your TOC
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = arcpy.mapping.ListLayers(mxd, "Layer you want to Buffer", df)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "'layer' variable instantiated."

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Create a Variable to hold your Output FC so that you can add it to the Map after it
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #is created by the buffer tool.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_fc ="Layer_Buffer"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "'out_fc' variable instantiated."

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Establish your Workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; workspace = arcpy.env.workspace = "C:\Temp\MyFileGeodatabase.gdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Workspace set."

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Run the Buffer Analysis on your Layer. You could also specify the distance and unit
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #of measurement dynamically using Comboboxes for Each and use the 'selection' for
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #those Comboboxes as the input.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Buffering Layer..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis(layer, workspace + "\"" + out_fc, "2 Miles", "FULL", "ROUND", "ALL")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Buffer Operation Complete."

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Add the newly created Buffer Layer to your MXD
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Adding Buffer to Map Document"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, out_fc, "AUTO_ARRANGE")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Script Complete"
&lt;/PRE&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Save the Script and back out of the Install Folder. &lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Run the makeaddin.py script to compile the addin and generate the ESRI Addin file.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Double click on the ESRI Addin File to install it.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Open up the Python Window so you can see the Print Statements as the script progresses.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Modify the script as neccesary.&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Disclaimer: I just wrote this out of my head, I didn't test or compile it so you might need to do some tweaking to get it to work, but I think it should run 'out-of-the-box'.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:31:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-python-script-to-create-a-custom-tool/m-p/39078#M3107</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2021-12-10T21:31:23Z</dc:date>
    </item>
  </channel>
</rss>

