<?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: Connect script with a sub-menu entry within Python-Addin in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/connect-script-with-a-sub-menu-entry-within-python/m-p/270561#M20898</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually I figured it that way. Earlier, I assumed that there has to be a class which I have to link with menu entry but guide book pointed to the use of button for sub-menu to call respective script under that button class. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;**Right now, I am looking at possible way to get a message box with strings to select -- interactive string selection from message dialogue. I think it is not possible with pythonaddins current module options but hoping there to be a workaround for this. Sorry for posting off the topic text.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Apr 2013 22:02:22 GMT</pubDate>
    <dc:creator>IbraheemKhan1</dc:creator>
    <dc:date>2013-04-03T22:02:22Z</dc:date>
    <item>
      <title>Connect script with a sub-menu entry within Python-Addin</title>
      <link>https://community.esri.com/t5/python-questions/connect-script-with-a-sub-menu-entry-within-python/m-p/270559#M20896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have created a menu entry using "pythonaddins" and it contains 2 sub-menus. Two separate scripts have to be linked to the sub-menus which should be invoked one-by-one when I click on sub-menu entry. First sub-menu should be active and second greyed out. Please suggest how to do it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 09:51:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/connect-script-with-a-sub-menu-entry-within-python/m-p/270559#M20896</guid>
      <dc:creator>IbraheemKhan1</dc:creator>
      <dc:date>2013-03-21T09:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Connect script with a sub-menu entry within Python-Addin</title>
      <link>https://community.esri.com/t5/python-questions/connect-script-with-a-sub-menu-entry-within-python/m-p/270560#M20897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Khan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It's not clear what you are trying to do but one thing is certain, you can't execute a function with a menu or submenu. Menus are just containers for buttons or sub-menus. Creating a Menu or Sub-Menu does not instantiate an Object which is neccesary for you to be able to do anything. With Python Addins, you have three choices to create an Object. A Button, Tool or Combobox. Any of these three will instantiate an Object which you can then leverage to execute your scripts.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It sounds like you want to execute an external script based on a button click. To do this, you need to create a Toolbar and a Button, or Two buttons if you have two scripts unless you want to do some other conditional formatting, but based on your limited description, I don't think you do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once you create the Toolbar and 2 buttons, all you have to do is create 2 variables which reference the absolute path to the scripts you want to execute. Then use the execfile function to execute them when you click on the button.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is an example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
import pythonaddins

class Button1(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for LYR.BaseMap_Sat (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; script1 = "C:\Temp\Module1.py"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; execfile(script)

class Button2(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for LYR.BaseMap_Sat (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; script2 = "C:\Temp\Module2.py"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; execfile(script2)
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want one of the buttons to be greyed out, then you need to change the 'enabled' property for that button to 'False'. If you want it to be enabled/disabled based on the status of the other button, then you need to do some conditional statements. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suggest you take a look at the &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/What_is_a_Python_add_in/014p00000025000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;Python Addin Guidebook&lt;/A&gt;&lt;SPAN&gt; for more information.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Happy Scripting!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;John&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:13:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/connect-script-with-a-sub-menu-entry-within-python/m-p/270560#M20897</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2021-12-11T13:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Connect script with a sub-menu entry within Python-Addin</title>
      <link>https://community.esri.com/t5/python-questions/connect-script-with-a-sub-menu-entry-within-python/m-p/270561#M20898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually I figured it that way. Earlier, I assumed that there has to be a class which I have to link with menu entry but guide book pointed to the use of button for sub-menu to call respective script under that button class. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;**Right now, I am looking at possible way to get a message box with strings to select -- interactive string selection from message dialogue. I think it is not possible with pythonaddins current module options but hoping there to be a workaround for this. Sorry for posting off the topic text.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 22:02:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/connect-script-with-a-sub-menu-entry-within-python/m-p/270561#M20898</guid>
      <dc:creator>IbraheemKhan1</dc:creator>
      <dc:date>2013-04-03T22:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Connect script with a sub-menu entry within Python-Addin</title>
      <link>https://community.esri.com/t5/python-questions/connect-script-with-a-sub-menu-entry-within-python/m-p/270562#M20899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There's no way in Python Addins to do that with a Messagebox that I can currently think of. You could certainly use a Combobox, with the items populated with your strings and the 'selection' as the method to call whatever function you want.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Apr 2013 02:14:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/connect-script-with-a-sub-menu-entry-within-python/m-p/270562#M20899</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2013-04-04T02:14:31Z</dc:date>
    </item>
  </channel>
</rss>

