<?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 Separating business logic and add-in script [Python Add-In] in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/separating-business-logic-and-add-in-script-python/m-p/666396#M51736</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was hoping someone could fill me in on how I can properly seperate my python addins' business logic and the main add-in script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The config.xml file lists:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;lt;AddIn language="PYTHON" library="PythonAddIn_addin.py" namespace="PythonAddIn_addin"&amp;gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;in its top most level. My library will contain more than just the default PythonAddIn_addin.py file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ideally, I would like to be able to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;from Install.businesslogic import Analytics&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;to import my business logic function definition Analytics().&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Currently, this breaks my application, while keeping all the needed code within the PythonAddIn_addin.py file works. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The moment I try to import code from a relative path (within the Install folder), the add-in breaks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ideas? I couldn't live with all my business logic sitting inside the PythonAddIn_addin.py file... its getting huge.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 19 Jun 2012 19:31:54 GMT</pubDate>
    <dc:creator>MichaelMarkieta</dc:creator>
    <dc:date>2012-06-19T19:31:54Z</dc:date>
    <item>
      <title>Separating business logic and add-in script [Python Add-In]</title>
      <link>https://community.esri.com/t5/python-questions/separating-business-logic-and-add-in-script-python/m-p/666396#M51736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was hoping someone could fill me in on how I can properly seperate my python addins' business logic and the main add-in script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The config.xml file lists:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;lt;AddIn language="PYTHON" library="PythonAddIn_addin.py" namespace="PythonAddIn_addin"&amp;gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;in its top most level. My library will contain more than just the default PythonAddIn_addin.py file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ideally, I would like to be able to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;from Install.businesslogic import Analytics&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;to import my business logic function definition Analytics().&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Currently, this breaks my application, while keeping all the needed code within the PythonAddIn_addin.py file works. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The moment I try to import code from a relative path (within the Install folder), the add-in breaks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ideas? I couldn't live with all my business logic sitting inside the PythonAddIn_addin.py file... its getting huge.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jun 2012 19:31:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/separating-business-logic-and-add-in-script-python/m-p/666396#M51736</guid>
      <dc:creator>MichaelMarkieta</dc:creator>
      <dc:date>2012-06-19T19:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Separating business logic and add-in script [Python Add-In]</title>
      <link>https://community.esri.com/t5/python-questions/separating-business-logic-and-add-in-script-python/m-p/666397#M51737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Rather than &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;Install.businesslogic&lt;/SPAN&gt;&lt;SPAN&gt;, does &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;import businesslogic&lt;/SPAN&gt;&lt;SPAN&gt; work? It should. If not, try &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;sys.path.append(os.path.dirname(__file__))&lt;/SPAN&gt;&lt;SPAN&gt; before your import thought I thought I made relative imports work.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jun 2012 20:14:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/separating-business-logic-and-add-in-script-python/m-p/666397#M51737</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-06-19T20:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Separating business logic and add-in script [Python Add-In]</title>
      <link>https://community.esri.com/t5/python-questions/separating-business-logic-and-add-in-script-python/m-p/666398#M51738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Rather than &lt;SPAN style="font-family:Courier New;"&gt;Install.businesslogic&lt;/SPAN&gt;, does &lt;SPAN style="font-family:Courier New;"&gt;import businesslogic&lt;/SPAN&gt; work? It should. If not, try &lt;SPAN style="font-family:Courier New;"&gt;sys.path.append(os.path.dirname(__file__))&lt;/SPAN&gt; before your import thought I thought I made relative imports work.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I was about to update my question with that exact answer!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For those who come across the same problem. You can seperate your code into bite sized chunks and import them as modules as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import os, sys; append relative directory to path
import os
import sys
sys.path.append(os.path.dirname(__file__))
import arcpy
import pythonaddins

# Import your modules and add functions to namespace
from businesslogic import *&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:09:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/separating-business-logic-and-add-in-script-python/m-p/666398#M51738</guid>
      <dc:creator>MichaelMarkieta</dc:creator>
      <dc:date>2021-12-12T04:09:37Z</dc:date>
    </item>
  </channel>
</rss>

