<?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: Stopping Python addin script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489790#M38312</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Break prematurely ends a loop while return passes back a return value to the function caller (basically returns to where the code was previously).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 May 2016 00:15:14 GMT</pubDate>
    <dc:creator>AdrianWelsh</dc:creator>
    <dc:date>2016-05-09T00:15:14Z</dc:date>
    <item>
      <title>Stopping Python addin script</title>
      <link>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489786#M38308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to find a way to trap an error in a python addin and stop the script. For example, I want to test if the dataframes spatial reference is a particular coordinate system. If it is not that specific CS, then I want to have a popup messagebox explaing that the user needs to change the CS and then re-run the tool and then have the addin stop running. I've attempted a try/except statement with sys.exit(), however sys.exit() seems to kill ArcMap all together, instead of just stopping the script itself. Is there a better way to accomplish what I want?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if df.spatialReference.name in ("NAD_1983_BC_Environment_Albers", "NAD 1983 BC Environment Albers"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "No problem with the CS"
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise Exception
except Exception:
&amp;nbsp;&amp;nbsp;&amp;nbsp; pythonaddins.MessageBox("Change dataframe spatial reference to NAD_1983_BC_Environment_Albers and re-run tool", "Report Generator")
&amp;nbsp;&amp;nbsp;&amp;nbsp; raise sys.exit()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:33:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489786#M38308</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-12-11T21:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Stopping Python addin script</title>
      <link>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489787#M38309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mike,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I haven't tested this, but try replacing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="_jivemacro_uid_1462557018227697 jive_macro_code jive_text_macro" data-renderedposition="112_8_1332_16" jivemacro_uid="_1462557018227697"&gt;&lt;P&gt;raise sys.exit()&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14625570234007675" data-renderedposition="206_8_1332_16" jivemacro_uid="_14625570234007675"&gt;&lt;P&gt;break&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 17:50:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489787#M38309</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2016-05-06T17:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Stopping Python addin script</title>
      <link>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489788#M38310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jake. I like the break statement. I also think I figured out where I went wrong. I had some code after the try and except statement. I was using sys.exit to try to stop the script, when all I had to do it just move my code into the try portion of the statement instead of outside and then when the exception occured, the script stops without having to use some sort of closing/exit/quit statement. Silly little mistake.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 18:25:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489788#M38310</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2016-05-06T18:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Stopping Python addin script</title>
      <link>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489789#M38311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just use `return` to exit the current function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys,os
import arcpy
import pythonaddins

class btnThatDoesSomething(object):

&amp;nbsp;&amp;nbsp;&amp;nbsp; def onClick(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # df = etc...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if df.spatialReference.name not in ("NAD_1983_BC_Environment_Albers", "NAD 1983 BC Environment Albers"): 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pythonaddins.MessageBox("Change dataframe spatial reference to NAD_1983_BC_Environment_Albers and re-run tool", "Report Generator") 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Rest of script&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:33:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489789#M38311</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-11T21:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Stopping Python addin script</title>
      <link>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489790#M38312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Break prematurely ends a loop while return passes back a return value to the function caller (basically returns to where the code was previously).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 May 2016 00:15:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopping-python-addin-script/m-p/489790#M38312</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2016-05-09T00:15:14Z</dc:date>
    </item>
  </channel>
</rss>

