[GIS] How to Disable the add-in button when ArcMap is started

add-inarcmap

Question 1:How to Disable the add-in button when the ArcMap started,then I use the SelectByRectangletool select features,then the button enabled! I am a fresh man about the add-in.

Question 2:I made a menu as show ,As the figure shows, how to avoid the part of in red rectangle,because the menu do not have the child menu again,but it is show the arrow ,and part of the child menu.

I means the tool’s skin is gray,and it is not activate

question 1:tool gray, not activate

question 2 :My  custom toolbar with the menu click here

I am sorry about my poor engilsh

here is the question2's config.esriaddinx file:

<ArcMap>
  <Commands>
    <Button id="Yangtze_University_GRP_Mult" class="Mult" message="new" caption="test" tip="tip" category="Add-In Controls" image="Images\1.png" />
    <MultiItem id="ESRI_SelectionSample_MultiItem" caption="MultiItem AddIn" class="ZoomToLayerMultiItem" >
    </MultiItem>
  </Commands>
  <Menus>
    <!--main menu-->
    <Menu id="Yangtze_University_GRP_My_Menu" caption="MainMenu" isRootMenu="true">
      <Items>
        <Menu refID="Yangtze_University_GRP_My_Menu_2" />
        <Menu refID="Yangtze_University_GRP_My_Menu_1" />
      </Items>
    </Menu>
    <!--submenu-->
    <Menu id="Yangtze_University_GRP_My_Menu_2" caption="New file" isRootMenu="false">
      <Items>
        <!--<Button refID="Yangtze_University_GRP_Mult" />-->
        <Menu refID="Yangtze_University_GRP_My_Menu_3" />
        <Menu refID="Yangtze_University_GRP_My_Menu_4" />
        <Menu refID="Yangtze_University_GRP_My_Menu_5" />
        <MultiItem refID="ESRI_SelectionSample_MultiItem" />
      </Items>
    </Menu>
    <!--third menu-->
    <Menu id="Yangtze_University_GRP_My_Menu_3" caption="test1" isRootMenu="false" isShortcutMenu="true" />
    <Menu id="Yangtze_University_GRP_My_Menu_4" caption="test2" isRootMenu="false" isShortcutMenu="true" />
    <Menu id="Yangtze_University_GRP_My_Menu_5" caption="test3" isRootMenu="false" isShortcutMenu="true" />
  </Menus>
  <Toolbars>
    <Toolbar id="Yangtze_University_GRP_My_Toolbar" caption="toolbar" showInitially="true">
      <Items>
        <Menu refID="Yangtze_University_GRP_My_Menu" />
      </Items>
    </Toolbar>
  </Toolbars>
</ArcMap>

Best Answer

To have a button enabled pending a condition, you first have to change one of the parameters in the Config.esriaddinx file. This is in the help under Delay loading section. You have to include 'onDemand="false"' in the button declaration, like this

<Button id="ESRI_SelectionSample_ToggleDockWinBtn" class="ToggleDockWinBtn" caption="Toggle Dockable Window" category="Framework AddIn Samples" image="Images\ToggleDockWinBtn.png" tip="Toggle dockable window." message="Toggle dockable window." onDemand="false">

Then in the code for your button, you'll have to add in the OnUpdate sub, which will enable or diable the button depending on the condition. It sounds like you'll want to check whether there are selected features in your feature class.

Protected Overrides Sub OnUpdate()

    Me.Enabled = pSelectionSet.Count > 0

End Sub

For your second question, can you post your Config.esriaddinx file?

*Edit

Here is the Config.esriaddinx I use to create this toolbar for an extension.

enter image description here

<ArcMap>
  <Commands>
    <Button id="Biogeography_Branch_HabitatDigitizer_10_ImportScheme" class="ImportScheme" message="Import Classification Scheme from Table" caption="Import from Table" tip="Import Scheme from Table" category="Habitat Digitizer" image="Images\ImportScheme_1.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_Compatibility" class="Compatibility" message="Check shapefile/classification scheme compatibility" caption="Check Compatibility" tip="Check the shapefile for fields needed in classification scheme" category="Habitat Digitizer" image="Images\Compatibility.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_CreateLegend" class="CreateLegend" message="Add Legend to existing shapefile from classification scheme." caption="Add Legend" tip="Add Legend to existing shapefile from classification scheme." category="Habitat Digitizer" image="Images\CreateLegend.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_AttributeSelection" class="AttributeSelection" message="Attribute Selection" caption="Attribute Selection" tip="Attribute Selection" category="Habitat Digitizer" image="Images\AttributeSelection.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_ExportScheme" class="ExportScheme" message="Export Classification Scheme to Table" caption="Export Scheme" tip="Export Scheme to Table" category="Habitat Digitizer" image="Images\ExportScheme.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_ExportSchemeAsText" class="ExportSchemeAsText" message="Save Classification Scheme to Text File" caption="Save to Text" tip="Save Scheme to Text File" category="Add-In Controls" image="Images\ExportSchemeAsText.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_FieldInfo" class="FieldInfo" message="View Field Requirements for Classification Scheme" caption="View Field Information" tip="View Field Requirements for Classification Scheme" category="Habitat Digitizer" image="Images\FieldInfo.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_Integration" class="Integration" message="Automatically integrate layer when exiting Edit mode" caption="Automatically Integrate" tip="Automatically integrate layer when exiting Edit mode" category="Habitat Digitizer" image="Images\Integration.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_ModifyScheme" class="ModifyScheme" message="Modify existing classification scheme" caption="Modify Existing Scheme" tip="Modify existing classification scheme" category="Habitat Digitizer" image="Images\ModifyScheme.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_NewFeatureClass" class="NewFeatureClass" message="Create new feature class" caption="New Feature Class" tip="Create new feature class" category="Habitat Digitizer" image="Images\NewFeatureClass.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_NewScheme" class="NewScheme" message="Create new classification scheme" caption="New scheme" tip="Create new classification scheme" category="Habitat Digitizer" image="Images\NewScheme.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_RepairMismatch" class="RepairMismatch" message="Repairs mismatch between ID and attributes in shapefile" caption="Repair Attributes" tip="Repairs mismatch between ID and attributes in shapefile" category="Habitat Digitizer" image="Images\RepairMismatch.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_Settings" class="Settings" message="Set Scale and MMU Settings" caption="Settings" tip="Set Scale and MMU Settings" category="Habitat Digitizer" image="Images\Settings.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_ShowDictionary" class="ShowDictionary" message="View Classification Scheme Information" caption="View Scheme Information" tip="View Classification Scheme Information" category="Habitat Digitizer" image="Images\ShowDictionary.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_ViewClassificationScheme" class="ViewClassificationScheme" message="View Classification Scheme Hierarchy" caption="View Scheme Hierarchy" tip="View Classification Scheme Hierarchy" category="Habitat Digitizer" image="Images\ViewClassificationScheme.png" onDemand="false" />
    <Tool id="Biogeography_Branch_HabitatDigitizer_10_MMUGraphic" class="MMUGraphic" message="Add MMU Box" caption="Add MMU Box" tip="Add MMU box to display" category="Habitat Digitizer" image="Images\MMUGraphic_1.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_ValidateSDE" class="ValidateSDE" message="Validate scheme for SDE workspaces" caption="Validate scheme for SDE" tip="Validate scheme for SDE workspaces" category="Habitat Digitizer" image="Images\ValidateSDE_1.png" onDemand="false" />
    <Button id="Biogeography_Branch_HabitatDigitizer_10_ViewValidation" class="ViewValidation" message="Show Validated Workspaces" caption="Show Validated Workspaces" tip="Show Validated Workspaces" category="Habitat Digitizer" image="Images\ViewValidation_1.png" onDemand="false" />
  </Commands>
  <Extensions>
    <Extension id="Biogeography_Branch_HabitatDigitizer_10_Extension" class="Extension" productName="Habitat Digitizer" showInExtensionDialog="true" autoLoad="true">
      <Description>Habitat Digitizer Extension 6.0&#xD;&#xA;NOAA/NOS/NCCOS/CCMA/Biogeography Branch&#xD;&#xA;&#xD;&#xA;Provides the ability to use hierarchical classification schemes to &#xD;&#xA;rapidly delineate and attribute polygons, lines, and points.</Description>
    </Extension>
  </Extensions>
  <Toolbars>
    <Toolbar id="Biogeography_Branch_HabitatDigitizer_10_Habitat_Digitizer_Toolbar_1" caption="Habitat Digitizer" showInitially="false">
      <Items>
        <Menu refID="Biogeography_Branch_HabitatDigitizer_10_Habitat_Digitizer" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_NewFeatureClass" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_MMUGraphic" />
      </Items>
    </Toolbar>
  </Toolbars>
  <Menus>
    <Menu id="Biogeography_Branch_HabitatDigitizer_10_Habitat_Digitizer" caption="Habitat Digitizer" isRootMenu="true">
      <Items>
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_NewScheme" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_ModifyScheme" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_ImportScheme" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_ValidateSDE" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_ExportScheme" separator="true" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_ExportSchemeAsText" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_ViewClassificationScheme" separator="true" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_ViewValidation" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_ShowDictionary" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_FieldInfo" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_Compatibility" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_RepairMismatch" separator="true" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_CreateLegend" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_Settings" separator="true" />
        <Button refID="Biogeography_Branch_HabitatDigitizer_10_Integration" separator="true" />
      </Items>
    </Menu>
  </Menus>
  <Editor>
    <Extensions>
      <Extension id="Biogeography_Branch_HabitatDigitizer_10_EditorExtension" class="EditorExtension" />
    </Extensions>
  </Editor>
</ArcMap>
Related Question