I’m working on an internal project that seems to be worth sharing externally. I’m looking at the potential for run-time modification (thinking mainly about translation) of tooltips displayed by AutoCAD.
The first step towards realising this is clearly to determine when tooltips are going to be displayed and to establish the content of these tooltips.
Here’s some C# code that does this (written with Visual Studio 2010, so users of prior versions may need to swap out my lambda function for a delegate or even a full event-handler function). You’ll also need to include AdWindows.dll in addition to the typical assembly references.
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace DumpTooltips
{
public class Commands
{
[CommandMethod("DUMPTT")]
public void DumpTooltips()
{
Document doc =
Autodesk.AutoCAD.ApplicationServices.Application.
DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Autodesk.Windows.ComponentManager.ToolTipOpened +=
(s, e) =>
{
Autodesk.Internal.Windows.ToolTip tt =
s as Autodesk.Internal.Windows.ToolTip;
if (tt != null)
{
Autodesk.Windows.RibbonToolTip rtt =
tt.Content as Autodesk.Windows.RibbonToolTip;
if (rtt == null)
{
// Basic tooltip
ed.WriteMessage(
"\nTooltip containing basic content \"{0}\".\n",
tt.Content
);
}
else
{
// Enhanced tooltips
ed.WriteMessage(
"\nTooltip containing enhanced content \"{0}\".\n",
rtt.Content
);
}
}
};
}
}
}
I’m not fully happy about relying on an Autodesk.Internal class (even if just one layer of indirection when getting the data). Relying on this in a production implementation would be risky, as it’s clearly subject to change without warning.
When we run the DUMPTT command, whenever the user hovers over a UI element that displays an extended tooltip (from the ribbon or toolbars), the basic text gets dumped to the command-line. I won’t actually take a screenshot of this in action, but it works well enough.
Next we’ll look at getting – and then modifying – the extended contents of these tooltips.