Enable / disable a tool depending on data / layout view

2792
4
03-31-2011 01:22 AM
JanBurdziej1
New Contributor II
I have an ArcGIS 10 add-in (IDE VB.NET Express 2008) with custom toolbar and a custom tool on it. I want this tool to be enabled in data view and disabled in layout view.

What is the best way to achieve this using Arc Objects?

Any help appreciated.

Cheers,
Jan
0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor
This is the code that disables a command button if ArcMap is in Layout mode. Don't forget to also make the changes to the Config.esriaddinx file discussed here to make the button enabled or disabled on startup.

   Protected Overrides Sub OnUpdate()
        'Enabled = My.ArcMap.Application IsNot Nothing
        If TypeOf pMxDoc.ActiveView Is ESRI.ArcGIS.Carto.IPageLayout Then
            Enabled = False
        ElseIf TypeOf pMxDoc.ActiveView Is ESRI.ArcGIS.Carto.IMap Then
            Enabled = True
        End If
    End Sub
0 Kudos
JanBurdziej1
New Contributor II
Thanks! It works great. I was missing this OnDemand tag in Config.esriaddinx file.
Best regards,
Jan
0 Kudos
FernandoMendoza-Jara
New Contributor
I am doing the same task. My tool still not working. What do you mean with "OnDemand tag in Config.esriaddinx file"?
0 Kudos
JanBurdziej1
New Contributor II
While defining your tool in Config.esriaddin use onDemad="false" parameter, see the example below:

    <ArcMap>
      <Commands>
        <Tool id="YOUR-TOOL-ID" onDemand="false" class="YOUR-CLASS" message="..." caption="..." tip="..." category="YOUR-CATEGORY" image="..." />
      </Commands>


I am doing the same task. My tool still not working. What do you mean with "OnDemand tag in Config.esriaddinx file"?
0 Kudos