Disable a command button within an Add-In

3412
7
10-17-2013 08:14 AM
by Anonymous User
Not applicable
Original User: Genaro Garcia

I need to disable a command button within an Add-In when ArcMap is started.

I added "OnDemand = false" option in the Config.esriaddinx, but still not working.
It actually crashes ArcMap. See attached document to view the code and error message.
I may be doing something wrong, but not sure.

Any help is greatly appreciated.
0 Kudos
7 Replies
GenaroGarcia
New Contributor III
I solved the crashing issue.
1. I removed "OnDemand = false" from the Config.esriaddinx.
2. I deleted the current add-in.
3. I deleted the Normal.mnt.

Now my question is, How do you disable a command button add-in when ArcMap is started?
0 Kudos
by Anonymous User
Not applicable
Original User: kenbuja

Here's an example of a tool where a command button is enabled if there are two registry keys.

This is the Config.esriaddinx

  <AddIn language="CLR" library="MPA_SPARC.dll" namespace="MPA_SPARC">
    <ArcMap>
      <Commands>
        <Button id="Biogeography_Branch_MPA_SPARC_btnAnalyze" class="btnAnalyze" message="Start the main Analysis tool" caption="Analyze" tip="Analyze" category="Biogeography Branch Add-In Controls" image="Images\btnAnalyze.png" onDemand="false" />



and this is the code for the command

Public Class btnAnalyze
    Inherits ESRI.ArcGIS.Desktop.AddIns.Button

    Public Sub New()

    End Sub

    Protected Overrides Sub OnClick()
       
        //the click task

    End Sub

    Protected Overrides Sub OnUpdate()

        Dim KeyExist As Boolean

        KeyExist = (My.Computer.Registry.GetValue("HKEY_CURRENT_USER\SOFTWARE\Biogeography Branch\SPARC", "MPA", Nothing) IsNot Nothing)  And
            (My.Computer.Registry.GetValue("HKEY_CURRENT_USER\SOFTWARE\Biogeography Branch\SPARC", "Resources", Nothing) IsNot Nothing)
        Enabled = (My.ArcMap.Application IsNot Nothing) And KeyExist

    End Sub

End Class
0 Kudos
GenaroGarcia
New Contributor III
I inserted, onDemand ="false" statement in the button of the config again, which caused ArcMap to crash.
I getting the same results as the previous time.


<ESRI.Configuration xmlns="http://schemas.esri.com/Desktop/AddIns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Name>OKC_FixArcs_Cmd</Name>
  <AddInID>{2b2b3fd4-6c5e-45b6-b378-232e81da046f}</AddInID>
  <Description>"Smooths the arc by inserting vertices using the density method only on polyline and polygon feature classes"</Description>
  <Version>1.0</Version>
  <Image>Images\OKC_FixArcs_Cmd.png</Image>
  <Author>Genaro L. Garcia, Jr.</Author>
  <Company>City of Oklahoma City</Company>
  <Date>10/15/2013</Date>
  <Targets>
    <Target name="Desktop" version="10.0" />
  </Targets>
  <AddIn language="CLR" library="OKC_FixArcs_Cmd.dll" namespace="OKC_FixArcs_Cmd">
    <ArcMap>
      <Commands>
          <Button
            id="City_of_Oklahoma_OKC_FixArcs_Cmd_OKC_FixArcs" class="OKC_FixArcs" tip="Fix Arcs" message="Smooths the arc by inserting vertices using the density method only on polyline and polygon feature classes" caption="Fix Arcs Cmd" category="Add-In Controls" image="Images\OKC_FixArcs_Cmd.png" onDemand="false />
      </Commands>
    </ArcMap>
  </AddIn>
</ESRI.Configuration>
0 Kudos
by Anonymous User
Not applicable
Original User: kenbuja

Do you have the quotes closed correctly? Your line finishes with this

 onDemand="false />


which is missing the final quote

 onDemand="false" />
0 Kudos
GenaroGarcia
New Contributor III
Yes, Ken, I fix that problem, onDemand = "false".
Still crashes ArcMap.

At this point, I wrote code to check to see the edit status in order to us the command tool.
0 Kudos
by Anonymous User
Not applicable
Original User: kenbuja

Here's how I have one button in an addin that only is enabled when the editor has started.

    Protected Overrides Sub OnUpdate()

        Me.Enabled = My.ArcMap.Editor.EditState <> ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing

    End Sub


The next thing to do is to put Try..Catch blocks in your code to see where and why it is crashing
0 Kudos
JeraldAllen
New Contributor III

Late in the game I know, I did however just hit this issue and resolved it by using onDemand="0" instead of onDemand="false"

0 Kudos