<?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: Embedding Python Tool in Add-In File in Python AddIns Questions</title>
    <link>https://community.esri.com/t5/python-addins-questions/embedding-python-tool-in-add-in-file/m-p/1214280#M142</link>
    <description>&lt;P&gt;I'm now learning how to make a button step by step, and I'm having a problem while testing it: the toolbar is loaded successfully, I can click on it but&amp;nbsp; can't zoom to the selected feature, could someone please explain why this is happening?&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;C:\Users\lenovo\Documents\ArcGIS\AddIns\python_addin_project_Ren&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_Spruce__0-1663694193541.png" style="width: 216px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51652iEDF07C5ED1578318/image-dimensions/216x133?v=v2" width="216" height="133" role="button" title="_Spruce__0-1663694193541.png" alt="_Spruce__0-1663694193541.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#config.xml
&amp;lt;?xml version="1.0"?&amp;gt;
-&amp;lt;ESRI.Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.esri.com/Desktop/AddIns"&amp;gt;
&amp;lt;Name&amp;gt;Python Addin Demonstration&amp;lt;/Name&amp;gt;
&amp;lt;AddInID&amp;gt;{31e63974-b41b-4801-8000-007d0e28e03e}&amp;lt;/AddInID&amp;gt;
&amp;lt;Description&amp;gt;带有工具和按钮的 add-in demonstration&amp;lt;/Description&amp;gt;
&amp;lt;Version&amp;gt;0.1&amp;lt;/Version&amp;gt;
&amp;lt;Image&amp;gt;Images\Bug.png&amp;lt;/Image&amp;gt;
&amp;lt;Author&amp;gt;Sherry&amp;lt;/Author&amp;gt;
&amp;lt;Company&amp;gt;Great Fir&amp;lt;/Company&amp;gt;
&amp;lt;Date&amp;gt;09/21/2022&amp;lt;/Date&amp;gt;
-&amp;lt;Targets&amp;gt;
&amp;lt;Target version="10.1" name="Desktop"/&amp;gt;
&amp;lt;/Targets&amp;gt;
-&amp;lt;AddIn language="PYTHON" namespace="python_addin_project_Ren_addin" library="python_addin_project_Ren_addin.py"&amp;gt;
-&amp;lt;ArcMap&amp;gt;
-&amp;lt;Commands&amp;gt;
-&amp;lt;Button tip="Zoom to Selected Features" message="Zoom to Selected Features" image="Images\Zoom_to_Seleted_Features.png" id="python_addin_project_Ren_addin.button" class="Zoom_to_Selected_Features" category="Python Addin Demonstration" caption="Zoom to Selected Features"&amp;gt;
&amp;lt;Help heading="Zoom to Selected Features"&amp;gt;Zoom to Selected Features&amp;lt;/Help&amp;gt;
&amp;lt;/Button&amp;gt;
&amp;lt;/Commands&amp;gt;
&amp;lt;Extensions&amp;gt; &amp;lt;/Extensions&amp;gt;
-&amp;lt;Toolbars&amp;gt;
-&amp;lt;Toolbar id="python_addin_project_Ren_addin.toolbar" category="Python Addin Demonstration" caption="Toolbar_1" showInitially="true"&amp;gt;
-&amp;lt;Items&amp;gt;
&amp;lt;Button refID="python_addin_project_Ren_addin.button"/&amp;gt;
&amp;lt;/Items&amp;gt;
&amp;lt;/Toolbar&amp;gt;
&amp;lt;/Toolbars&amp;gt;
&amp;lt;Menus&amp;gt; &amp;lt;/Menus&amp;gt;
&amp;lt;/ArcMap&amp;gt;
&amp;lt;/AddIn&amp;gt;
&amp;lt;/ESRI.Configuration&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;C:\Users\lenovo\Documents\ArcGIS\AddIns\Desktop10.1\{31e63974-b41b-4801-8000-007d0e28e03e}&amp;nbsp; --&amp;gt;&amp;nbsp; &amp;nbsp;.esriaddin&amp;nbsp; path&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#makeaddin.py
import os
import re
import zipfile

current_path = os.path.dirname(os.path.abspath(__file__))

out_zip_name = os.path.join(current_path, 
                            os.path.basename(current_path) + ".esriaddin")

BACKUP_FILE_PATTERN = re.compile(".*_addin_[0-9]+[.]py$", re.IGNORECASE)

def looks_like_a_backup(filename):
    return bool(BACKUP_FILE_PATTERN.match(filename))

with zipfile.ZipFile(out_zip_name, 'w', zipfile.ZIP_DEFLATED) as zip_file:
    for filename in ('config.xml', 'README.txt', 'makeaddin.py'):
        zip_file.write(os.path.join(current_path, filename), filename)
    dirs_to_add = ['Images', 'Install']
    for directory in dirs_to_add:
        for (path, dirs, files) in os.walk(os.path.join(current_path,
                                                        directory)):
            archive_path = os.path.relpath(path, current_path)
            found_file = False
            for file in (f for f in files if not looks_like_a_backup(f)):
                archive_file = os.path.join(archive_path, file)
                print(archive_file)
                zip_file.write(os.path.join(path, file), archive_file)
                found_file = True
            if not found_file:
                zip_file.writestr(os.path.join(archive_path,
                                               'placeholder.txt'),
                                  "(Empty directory)")

#Zoom_to_Seleted_Features.py
# Implementation of OnClick method of Button's class
def onClick(self):
        # Get the current map document and the first data frame.
        mxd = arcpy.mapping.MapDocument('current')
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        # Call the zoomToSelectedFeatures() method of the data frame class
        df.zoomToSelectedFeatures()

#python_addin_project_Ren_addin.py
#C:\Users\lenovo\Documents\ArcGIS\AddIns\python_addin_project_Ren\Install
import arcpy
import pythonaddins

class Zoom_to_Selected_Features(object):
    """Implementation for python_addin_project_Ren_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        pass&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Sep 2022 17:29:00 GMT</pubDate>
    <dc:creator>_Spruce_</dc:creator>
    <dc:date>2022-09-20T17:29:00Z</dc:date>
    <item>
      <title>Embedding Python Tool in Add-In File</title>
      <link>https://community.esri.com/t5/python-addins-questions/embedding-python-tool-in-add-in-file/m-p/1009713#M138</link>
      <description>&lt;P&gt;I've successfully created a toolbar using the Esri Add-In wizard. Each button references a different tool from a custom Python script toolbox I've developed.&lt;/P&gt;&lt;P&gt;I've made an iteration of the Add-In that references each script tool in the toolbox file, and it works perfect.&lt;/P&gt;&lt;P&gt;Now my question: can I embed the script from the tools into the Add-In script, instead of just referencing the *.tbx file? And by doing so, will this let me distribute the Add-In by itself without having to also distribute the toolbox for it to work? I've seen a few articles/posts about this, but they've left me confused as to how to do this. Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 13:50:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/embedding-python-tool-in-add-in-file/m-p/1009713#M138</guid>
      <dc:creator>JasonLearned1</dc:creator>
      <dc:date>2020-12-15T13:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Embedding Python Tool in Add-In File</title>
      <link>https://community.esri.com/t5/python-addins-questions/embedding-python-tool-in-add-in-file/m-p/1064663#M140</link>
      <description>&lt;P&gt;hello am a student . please can you teach me how to add a button and to do like the great job you did . please&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 15:03:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/embedding-python-tool-in-add-in-file/m-p/1064663#M140</guid>
      <dc:creator>ines-mahmoud</dc:creator>
      <dc:date>2021-06-03T15:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Embedding Python Tool in Add-In File</title>
      <link>https://community.esri.com/t5/python-addins-questions/embedding-python-tool-in-add-in-file/m-p/1064740#M141</link>
      <description>&lt;P&gt;The how-to guide can be found here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/analyze/python-addins/creating-an-add-in-project.htm" target="_blank"&gt;https://desktop.arcgis.com/en/arcmap/latest/analyze/python-addins/creating-an-add-in-project.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You have to download the&amp;nbsp;&lt;EM&gt;&lt;SPAN class="uicontrol"&gt;Python Add-In Wizard&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;first, but it is easy and shouldn't require administrative rights on your computer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I hope this helps. Best wishes!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 16:38:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/embedding-python-tool-in-add-in-file/m-p/1064740#M141</guid>
      <dc:creator>JasonLearned1</dc:creator>
      <dc:date>2021-06-03T16:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Embedding Python Tool in Add-In File</title>
      <link>https://community.esri.com/t5/python-addins-questions/embedding-python-tool-in-add-in-file/m-p/1214280#M142</link>
      <description>&lt;P&gt;I'm now learning how to make a button step by step, and I'm having a problem while testing it: the toolbar is loaded successfully, I can click on it but&amp;nbsp; can't zoom to the selected feature, could someone please explain why this is happening?&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;C:\Users\lenovo\Documents\ArcGIS\AddIns\python_addin_project_Ren&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_Spruce__0-1663694193541.png" style="width: 216px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51652iEDF07C5ED1578318/image-dimensions/216x133?v=v2" width="216" height="133" role="button" title="_Spruce__0-1663694193541.png" alt="_Spruce__0-1663694193541.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#config.xml
&amp;lt;?xml version="1.0"?&amp;gt;
-&amp;lt;ESRI.Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.esri.com/Desktop/AddIns"&amp;gt;
&amp;lt;Name&amp;gt;Python Addin Demonstration&amp;lt;/Name&amp;gt;
&amp;lt;AddInID&amp;gt;{31e63974-b41b-4801-8000-007d0e28e03e}&amp;lt;/AddInID&amp;gt;
&amp;lt;Description&amp;gt;带有工具和按钮的 add-in demonstration&amp;lt;/Description&amp;gt;
&amp;lt;Version&amp;gt;0.1&amp;lt;/Version&amp;gt;
&amp;lt;Image&amp;gt;Images\Bug.png&amp;lt;/Image&amp;gt;
&amp;lt;Author&amp;gt;Sherry&amp;lt;/Author&amp;gt;
&amp;lt;Company&amp;gt;Great Fir&amp;lt;/Company&amp;gt;
&amp;lt;Date&amp;gt;09/21/2022&amp;lt;/Date&amp;gt;
-&amp;lt;Targets&amp;gt;
&amp;lt;Target version="10.1" name="Desktop"/&amp;gt;
&amp;lt;/Targets&amp;gt;
-&amp;lt;AddIn language="PYTHON" namespace="python_addin_project_Ren_addin" library="python_addin_project_Ren_addin.py"&amp;gt;
-&amp;lt;ArcMap&amp;gt;
-&amp;lt;Commands&amp;gt;
-&amp;lt;Button tip="Zoom to Selected Features" message="Zoom to Selected Features" image="Images\Zoom_to_Seleted_Features.png" id="python_addin_project_Ren_addin.button" class="Zoom_to_Selected_Features" category="Python Addin Demonstration" caption="Zoom to Selected Features"&amp;gt;
&amp;lt;Help heading="Zoom to Selected Features"&amp;gt;Zoom to Selected Features&amp;lt;/Help&amp;gt;
&amp;lt;/Button&amp;gt;
&amp;lt;/Commands&amp;gt;
&amp;lt;Extensions&amp;gt; &amp;lt;/Extensions&amp;gt;
-&amp;lt;Toolbars&amp;gt;
-&amp;lt;Toolbar id="python_addin_project_Ren_addin.toolbar" category="Python Addin Demonstration" caption="Toolbar_1" showInitially="true"&amp;gt;
-&amp;lt;Items&amp;gt;
&amp;lt;Button refID="python_addin_project_Ren_addin.button"/&amp;gt;
&amp;lt;/Items&amp;gt;
&amp;lt;/Toolbar&amp;gt;
&amp;lt;/Toolbars&amp;gt;
&amp;lt;Menus&amp;gt; &amp;lt;/Menus&amp;gt;
&amp;lt;/ArcMap&amp;gt;
&amp;lt;/AddIn&amp;gt;
&amp;lt;/ESRI.Configuration&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;C:\Users\lenovo\Documents\ArcGIS\AddIns\Desktop10.1\{31e63974-b41b-4801-8000-007d0e28e03e}&amp;nbsp; --&amp;gt;&amp;nbsp; &amp;nbsp;.esriaddin&amp;nbsp; path&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#makeaddin.py
import os
import re
import zipfile

current_path = os.path.dirname(os.path.abspath(__file__))

out_zip_name = os.path.join(current_path, 
                            os.path.basename(current_path) + ".esriaddin")

BACKUP_FILE_PATTERN = re.compile(".*_addin_[0-9]+[.]py$", re.IGNORECASE)

def looks_like_a_backup(filename):
    return bool(BACKUP_FILE_PATTERN.match(filename))

with zipfile.ZipFile(out_zip_name, 'w', zipfile.ZIP_DEFLATED) as zip_file:
    for filename in ('config.xml', 'README.txt', 'makeaddin.py'):
        zip_file.write(os.path.join(current_path, filename), filename)
    dirs_to_add = ['Images', 'Install']
    for directory in dirs_to_add:
        for (path, dirs, files) in os.walk(os.path.join(current_path,
                                                        directory)):
            archive_path = os.path.relpath(path, current_path)
            found_file = False
            for file in (f for f in files if not looks_like_a_backup(f)):
                archive_file = os.path.join(archive_path, file)
                print(archive_file)
                zip_file.write(os.path.join(path, file), archive_file)
                found_file = True
            if not found_file:
                zip_file.writestr(os.path.join(archive_path,
                                               'placeholder.txt'),
                                  "(Empty directory)")

#Zoom_to_Seleted_Features.py
# Implementation of OnClick method of Button's class
def onClick(self):
        # Get the current map document and the first data frame.
        mxd = arcpy.mapping.MapDocument('current')
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        # Call the zoomToSelectedFeatures() method of the data frame class
        df.zoomToSelectedFeatures()

#python_addin_project_Ren_addin.py
#C:\Users\lenovo\Documents\ArcGIS\AddIns\python_addin_project_Ren\Install
import arcpy
import pythonaddins

class Zoom_to_Selected_Features(object):
    """Implementation for python_addin_project_Ren_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        pass&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 17:29:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/embedding-python-tool-in-add-in-file/m-p/1214280#M142</guid>
      <dc:creator>_Spruce_</dc:creator>
      <dc:date>2022-09-20T17:29:00Z</dc:date>
    </item>
  </channel>
</rss>

