明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 951|回复: 0

Getting the basic content from AutoCAD tooltips using .NET

[复制链接]
发表于 2011-7-9 16:01:30 | 显示全部楼层 |阅读模式

作者:kean

原文地址:http://through-the-interface.typepad.com/through_the_interface/2011/07/getting-the-basic-content-from-autocad-tooltips-using-net.html

 

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.

"觉得好,就打赏"
还没有人打赏,支持一下

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-12-24 07:51 , Processed in 0.170069 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表