Author Topic: Formatting in a RollOver ToolTip  (Read 6958 times)

0 Members and 1 Guest are viewing this topic.

Keith Brown

  • Swamp Rat
  • Posts: 601
Formatting in a RollOver ToolTip
« on: November 08, 2013, 11:42:39 AM »
Has anyone got the tooltips to work as described in this ADN Blog?  http://adndevblog.typepad.com/autocad/2013/03/formatting-in-rollover-tip.html
 
I simply copied and pasted the code into a new project, added the appropriate references and tested it and it didn't work.  All it displays in the tooltip is the formatting text and none of the information of the entity.  Am I missing something or is this another example of an ADN article that just doesn't work as explained?  Below is the code that I used.
 
Code - C#: [Select]
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.EditorInput;
  3. using Autodesk.AutoCAD.Runtime;
  4. namespace ToolTipFormatting
  5. {
  6.     public class Class1 : IExtensionApplication
  7.     {
  8.         void IExtensionApplication.Initialize()
  9.         {
  10.             Document activeDoc = Application.DocumentManager.MdiActiveDocument;
  11.             activeDoc.Editor.PointMonitor += new PointMonitorEventHandler(Editor_PointMonitor);
  12.         }
  13.         void Editor_PointMonitor(object sender, PointMonitorEventArgs e)
  14.         {
  15.             if (e.Context.GetPickedEntities().Length > 0)
  16.             {
  17.                 e.AppendToolTipText("Iam]]><LineBreak/><Bold>BOLD</Bold><LineBreak/>" +
  18.                                 "<![CDATA[Iam]]><LineBreak/><Italic>Italic</Italic>" +
  19.                                 "<LineBreak/><![CDATA[Iam Normal");
  20.             }
  21.         }
  22.         void IExtensionApplication.Terminate()
  23.         {
  24.             Document activeDoc = Application.DocumentManager.MdiActiveDocument;
  25.             if (activeDoc != null)
  26.             {
  27.                 activeDoc.Editor.PointMonitor -= new PointMonitorEventHandler(Editor_PointMonitor);
  28.             }
  29.         }
  30.     }
  31. }
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Formatting in a RollOver ToolTip
« Reply #1 on: November 08, 2013, 01:04:00 PM »
works as advertised here ACAD 2013 and 2014

What do you mean when you say
All it displays in the tooltip is the formatting text and none of the information of the entity
?

BlackBox

  • King Gator
  • Posts: 3770
Re: Formatting in a RollOver ToolTip
« Reply #2 on: November 08, 2013, 01:07:41 PM »
works as advertised here ACAD 2013 and 2014

Same here in Civil 3D 2012.
"How we think determines what we do, and what we do determines what we get."

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Formatting in a RollOver ToolTip
« Reply #3 on: November 08, 2013, 01:19:22 PM »
Hi,

To get it work the ROLLOVERTIPS sysvar have to be set to 1.
Speaking English as a French Frog

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Formatting in a RollOver ToolTip
« Reply #4 on: November 08, 2013, 02:38:29 PM »
works as advertised here ACAD 2013 and 2014

What do you mean when you say

This is all it displays
 
Code: [Select]
Iam]]><LineBreak/><Bold>BOLD</Bold><LineBreak/><![CDATA[Iam]]><LineBreak/><Italic>Italic</Italic><LineBreak/><![CDATA[Iam Normal
I have unloaded all other plugins and still get the same result.  I even loaded the autocad profile.
 
I saw it work once when I created a new document and then switched back to the original document that had the event handler added to it.  But trying it again got me nowhere.
 
I am running AutoCAD MEP 2014.  Switching to the AutoCAD profile got me the same results. 
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Formatting in a RollOver ToolTip
« Reply #5 on: November 08, 2013, 02:40:22 PM »
Hi,

To get it work the ROLLOVERTIPS sysvar have to be set to 1.

RollOverTips is set to one.  Turning it off will still allow the text shown above to still show in the tooltip but I suspect this is because the code doesn't check the state of the rollovertips parameter before appending to the tooltip.
 
This one has me scratching my head.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Formatting in a RollOver ToolTip
« Reply #6 on: November 08, 2013, 03:50:56 PM »
Is there some setting somewhere that controls how the tooltip will be displayed?  I have noticed that with the plugin loaded the tooltip itself is shaded almost as if its transparency is low.  Also if I just use the following line of code
 
Code: [Select]
e.AppendToolTipText("test");
It just shows the word "test" in the tooltip.  Shouldn't it also show the other information?
 
I know these questions are probably annoying for everyone but I am just trying to figure this out. 
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Formatting in a RollOver ToolTip
« Reply #7 on: November 08, 2013, 03:56:12 PM »
Is there some setting somewhere that controls how the tooltip will be displayed?  I have noticed that with the plugin loaded the tooltip itself is shaded almost as if its transparency is low

Figured this part out at least.  Under Dynamic Input Settings the Drafting Tooltip Appearance was set to override OS Settings for all drafting tooltips.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Formatting in a RollOver ToolTip
« Reply #8 on: November 08, 2013, 06:07:29 PM »
Well I have been able to get this to work in straight vanilla autocad 2014.  This is starting AutoCAD straight from a shortcut and not from switching profiles inside of AutoCAD MEP.  I also tried it in straight AutoCAD Architecture and was unable to get it to work.
Hopefully someone out there has one of these two programs and can test it on their machine so I can at least verify that it is something wrong in general or something wrong with my setup.
 
Thanks.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Formatting in a RollOver ToolTip
« Reply #9 on: November 08, 2013, 09:19:11 PM »
2013 Vanilla Worked
2013 MEP - Failed.
 
 

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Formatting in a RollOver ToolTip
« Reply #10 on: November 09, 2013, 08:58:54 AM »
Well at least I know I am not going crazy.
 
Since I now no longer have a development machine (threw it out the window last night from frustration) I have decided to move in another direction and have a handy stack of post it notes that I will stick to the screen when ever I hover over an object.  At this point I figure it will be faster anyway.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Formatting in a RollOver ToolTip
« Reply #11 on: November 09, 2013, 10:46:31 AM »
For some reason my boss didn't like the post-it note idea. (I thought it was bloody brilliant!) So I decided to wipe the slate clean and start from scratch.  If I couldn't customize the AutoCAD MEP tooltip then I would create my own.  Luckily AutoCAD/AutoCAD MEP has an api for that.  Here is my proof of concept code.
 
First the code to set the event handlers
 
Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Runtime;
  5. using Autodesk.Windows;
  6. using ToolTips;
  7.  
  8. [assembly: ExtensionApplication(typeof(ToolTipControl))]
  9. namespace ToolTips
  10. {
  11.     class ToolTipControl : IExtensionApplication
  12.     {
  13.         public void Initialize()
  14.         {
  15.             Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(this.DocumentManager_DocumentCreated);
  16.             Application.DocumentManager.DocumentToBeDestroyed += new DocumentCollectionEventHandler(this.DocumentManager_DocumentToBeDestroyed);
  17.             this.AddEvents(Application.DocumentManager.MdiActiveDocument);
  18.         }
  19.  
  20.         public void Terminate()
  21.         {
  22.             this.RemoveEvents(Application.DocumentManager.MdiActiveDocument);
  23.         }
  24.  
  25.         private void AddEvents(Document document)
  26.         {
  27.             ComponentManager.ToolTipOpened += new EventHandler(ToolTipHelper.ComponentManager_ToolTipOpened);
  28.             document.Editor.Rollover += new RolloverEventHandler(ToolTipHelper.Editor_Rollover);
  29.         }
  30.  
  31.         private void RemoveEvents(Document document)
  32.         {
  33.             document.Editor.Rollover -= new RolloverEventHandler(ToolTipHelper.Editor_Rollover);
  34.             ComponentManager.ToolTipOpened -= new EventHandler(ToolTipHelper.ComponentManager_ToolTipOpened);
  35.         }
  36.  
  37.         private void DocumentManager_DocumentCreated(object sender, DocumentCollectionEventArgs e)
  38.         {
  39.             this.AddEvents((e.Document));
  40.         }
  41.  
  42.         private void DocumentManager_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e)
  43.         {
  44.             this.RemoveEvents(e.Document);
  45.         }
  46.     }
  47. }
  48.  

And now the code to display the tooltip.
 
Code - C#: [Select]
  1. using Autodesk.Aec.Building.DatabaseServices;
  2. using Autodesk.AutoCAD.EditorInput;
  3. using System;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using ObjectId = Autodesk.AutoCAD.DatabaseServices.ObjectId;
  6.  
  7. namespace ToolTips
  8. {
  9.     public class ToolTipHelper
  10.     {
  11.         private static ObjectId toolTipObjectId = ObjectId.Null;
  12.        
  13.         public static void Editor_Rollover(Object sender, RolloverEventArgs e)
  14.         {
  15.             if (!e.Highlighted.IsNull)
  16.             {
  17.                 ObjectId[] objectsIds = e.Highlighted.GetObjectIds();
  18.                 if ((objectsIds != null) && (objectsIds.Length > 0))
  19.                 {
  20.                     if ((objectsIds[0].ObjectClass.Name == "AecbDbDuct") ||
  21.                         (objectsIds[0].ObjectClass.Name == "AecbDbDuctFitting") ||
  22.                         (objectsIds[0].ObjectClass.Name == "AecbDbDuctCustomFitting") ||
  23.                         (objectsIds[0].ObjectClass.Name == "AecbDbDuctFlex") ||
  24.                         (objectsIds[0].ObjectClass.Name == "AecbDbPipe") ||
  25.                         (objectsIds[0].ObjectClass.Name == "AecbDbPipeFitting") ||
  26.                         (objectsIds[0].ObjectClass.Name == "AecbDbPipeCustomFitting") ||
  27.                         (objectsIds[0].ObjectClass.Name == "AecbDbPipeFlex") ||
  28.                         (objectsIds[0].ObjectClass.Name == "AecbDbMvPart"))
  29.                     {
  30.                         toolTipObjectId = objectsIds[0];
  31.                     }
  32.                     else
  33.                     {
  34.                         toolTipObjectId = ObjectId.Null;
  35.                     }
  36.                 }
  37.                 else
  38.                 {
  39.                     toolTipObjectId = ObjectId.Null;
  40.                 }
  41.             }
  42.             else
  43.             {
  44.                 toolTipObjectId = ObjectId.Null;
  45.             }
  46.         }
  47.  
  48.         public static void ComponentManager_ToolTipOpened(object sender, EventArgs e)
  49.         {
  50.             if (toolTipObjectId != ObjectId.Null)
  51.             {
  52.                 var toolTip = sender as Autodesk.Internal.Windows.ToolTip;
  53.  
  54.                 // This check is needed to distinguish between the ribbon tooltips and the member tooltips
  55.                 if (toolTip != null)
  56.                 {
  57.                     Member member = null;
  58.                     using (
  59.                         Transaction transaction =
  60.                             HostApplicationServices.WorkingDatabase.TransactionManager.StartOpenCloseTransaction())
  61.                     {
  62.                         member = transaction.GetObject(toolTipObjectId, 0) as Member;
  63.                         transaction.Commit();
  64.                     }
  65.                     if (member != null)
  66.                     {
  67.                         var memberToolTip = new ToolTipMember();
  68.      
  69.                         // Switch the AutoCAD WPF ToolTip out with our WPF ToolTip
  70.                         toolTip.Content = memberToolTip;
  71.                         member.Dispose();
  72.                     }
  73.                 }
  74.                 // Reset the object for the next tooltip
  75.                 toolTipObjectId = ObjectId.Null;
  76.             }
  77.         }
  78.     }
  79. }

And finally the basic wpf xaml that was used to display a tooltip.
 
Code - C#: [Select]
  1. <UserControl x:Class="ToolTipFormatting.ToolTipMember"
  2.              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5.              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6.              mc:Ignorable="d"
  7.              d:DesignHeight="300" d:DesignWidth="300">
  8.     <Grid>
  9.         <TextBlock HorizontalAlignment="Left" Margin="30,24,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
  10.     </Grid>
  11. </UserControl>

 
The good news is that everything works correctly and my custom wpf usercontrol is displayed.  The bad news is that I know absolutely nothing about wpf and need to read up on it before I can populate a form with the information that I am looking to display.  So off to buy a book!
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Formatting in a RollOver ToolTip
« Reply #12 on: November 11, 2013, 07:58:13 AM »
I would recommend Adam Nathan "WPF Unleashed".

I love WPF and I write all my Autocad UI stuff exclusively in WPF.  If you're not familiar with MVVM you might want to look into that as well although this particular project probably doesn't need it.
Revit 2019, AMEP 2019 64bit Win 10

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Formatting in a RollOver ToolTip
« Reply #13 on: November 11, 2013, 08:35:14 AM »
I actually got that one and Pro WPF 4.5 in C# by Matthew MacDonald.  Digging into what I need now and hopefully can have this finished by the end of the day maybe.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013