<?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: onUpdate() for python add ins? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/onupdate-for-python-add-ins/m-p/236514#M18405</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Carl, did you ever find an answer or useful solution for this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 27 Apr 2018 20:40:13 GMT</pubDate>
    <dc:creator>BryanTaylor</dc:creator>
    <dc:date>2018-04-27T20:40:13Z</dc:date>
    <item>
      <title>onUpdate() for python add ins?</title>
      <link>https://community.esri.com/t5/python-questions/onupdate-for-python-add-ins/m-p/236513#M18404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When developing .Net add ins I would often use onUpdate() to determine when a button was enabled.&amp;nbsp; In the help file on Managing the State of Python Add-in types it says the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;SPAN style="color: #4d4d4d; font-family: Arial, Helvetica, sans-serif;"&gt;Add-in types--buttons, tools, and combo boxes--&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;are periodically notified to update their enabled and checked state&lt;/STRONG&gt;&lt;/SPAN&gt;. In Python, add-in types contain Boolean properties for &lt;/SPAN&gt;&lt;SPAN class="arcpyref" style="font-family: 'Courier New', Courier, monospace; font-weight: bold; color: #4d4d4d;"&gt;enabled&lt;/SPAN&gt;&lt;SPAN style="color: #4d4d4d; font-family: Arial, Helvetica, sans-serif;"&gt; and &lt;/SPAN&gt;&lt;SPAN class="arcpyref" style="font-family: 'Courier New', Courier, monospace; font-weight: bold; color: #4d4d4d;"&gt;checked&lt;/SPAN&gt;&lt;SPAN style="color: #4d4d4d; font-family: Arial, Helvetica, sans-serif;"&gt;. For example, you can set the add-in to be enabled or disabled and checked or unchecked during its initialization.&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4d4d4d; font-family: Arial, Helvetica, sans-serif;"&gt;When and how is this 'periodic notification' happening and how can I take advantage of this?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4d4d4d; font-family: Arial, Helvetica, sans-serif;"&gt;I have a tool that should only be enabled if the current layer has a selection.&amp;nbsp; Something like this to check if the current layer has a selection and if it does, enable the tool.&lt;/SPAN&gt;&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_14159152096571190" jivemacro_uid="_14159152096571190" modifiedtitle="true"&gt;
&lt;P&gt;layer = pythonaddins.GetSelectedTOCLayerOrDataFrame() &lt;/P&gt;
&lt;P&gt;if type(layer) is arcpy._mapping.Layer and not layer.isGroupLayer and arcpy.Describe(layer).fidSet&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True&lt;/P&gt;
&lt;P&gt;else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = False&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see that extensions allow some control over whether or not a tool is enabled, but I don't see anything that would be enabled if something simple like a selection on a layer was made.&amp;nbsp; This would be simple in .NET.&amp;nbsp; I also realize I could have a message box that pops up if there is no selection and says "Hey User!&amp;nbsp; Make a selection on this layer and try this button again" but in my mind the button should only be enabled if a selection exists on the current layer and should update whenever these types of changes occur.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also it would be great if I could control the location of where the button is placed.&amp;nbsp; For instance I'd love for this button to just appear in the feature layer&amp;gt;selection context menu, instead of telling users to put it there.&amp;nbsp; Again, easy in .NET, but doesn't seem to be possible in a python add-in.&amp;nbsp; This one, I'm not as concerned about for right now though...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 22:01:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/onupdate-for-python-add-ins/m-p/236513#M18404</guid>
      <dc:creator>CarlWalter</dc:creator>
      <dc:date>2014-11-13T22:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: onUpdate() for python add ins?</title>
      <link>https://community.esri.com/t5/python-questions/onupdate-for-python-add-ins/m-p/236514#M18405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Carl, did you ever find an answer or useful solution for this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Apr 2018 20:40:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/onupdate-for-python-add-ins/m-p/236514#M18405</guid>
      <dc:creator>BryanTaylor</dc:creator>
      <dc:date>2018-04-27T20:40:13Z</dc:date>
    </item>
  </channel>
</rss>

