Disabling AutoCAD tooltips using .NET

I wasn't planning on posting to this blog again, this week – three times per week is enough, I find, so I tend to save any leftovers for the week after – but this question James Maeding asked is very much related to this week's posts, and – in any case – I already have three fun posts planned for next week. 🙂

Here's the question James asked, again:

wish I had something to make tooltips disappear when needed. I like them on for many things, but then they get in the way sometimes, and you have to cancel all you are doing to turn them off. If only I could toggle them transparently with some command...maybe its easy I just have not thought about it too much.

It turned out to be pretty easy. Based on the approach I used – way back when – for automatic tooltip translation, I went and added an event handler that makes tooltips invisible as soon as they're shown. One interesting point is that I needed to make them visible again as they were closing (not that we see that). Otherwise they won't come back – in the same session – once we re-enable them by removing the event handler.

Here's the C# code defining the DTT and ETT commands, which disable and enable tooltips, respectively.

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.Windows;

 

namespace UserInterfaceManipulation

{

  public class Commands

  {

    [CommandMethod("DTT", CommandFlags.Transparent)]

    public static void DisableToolTips()

    {

      EnableTooltips(false);

    }

 

    [CommandMethod("ETT", CommandFlags.Transparent)]

    public static void EnableToolTips()

    {

      EnableTooltips(true);

    }

 

    public static void EnableTooltips(bool enable)

    {

      if (enable)

      {

        ComponentManager.ToolTipOpened -= OnToolTipOpened;

        ComponentManager.ToolTipClosed -= OnToolTipClosed;

      }

      else

      {

        ComponentManager.ToolTipOpened += OnToolTipOpened;

        ComponentManager.ToolTipClosed += OnToolTipClosed;

      }

    }

 

    private static void OnToolTipOpened(object sender, System.EventArgs e)

    {

      var tt = sender as System.Windows.Controls.ToolTip;

      if (tt != null)

      {

        tt.Visibility = System.Windows.Visibility.Hidden;

      }

    }

 

    private static void OnToolTipClosed(object sender, System.EventArgs e)

    {

      var tt = sender as System.Windows.Controls.ToolTip;

      if (tt != null)

      {

        tt.Visibility = System.Windows.Visibility.Visible;

      }

    }

  }

}

 

Here are the commands in action:

 

Disabling and re-enabling tooltips

5 responses to “Disabling AutoCAD tooltips using .NET”

  1. right on, another gem from the Walmster!

  2. hmm, I' wanting to run these while the plot and options dialogs are open, so no command line access. Is there a way to feed input to autocad in such a state? That might end up being a tougher challenge as I cannot think of anything tools that do that.

    1. Not via a command, but you could check a sysvar that dictates whether they get disabled when the PLOT & OPTIONS commands start.

      Kean

      1. the comments number is working again 🙂
        I am thinking this would be a good feature request for general acad - toggle tooltips with F10 or something. This really makes me wonder if its right under our noses by using a menu somehow. thx as always.

Leave a Reply to Jamed Maeding Cancel reply

Your email address will not be published. Required fields are marked *