Video Animated Ribbon Item Tooltip

We already discussed a number of interesting things you can do with the Revit ribbon and user interface, many inspired by Rudolf Honke’s exploration of uses of the .NET

UI Automation
functionality.

Here is a related contribution by Victor Chekalin, or Виктор Чекалин, fleshed out from his answer to Rudolf’s

question on animating a ribbon item tooltip
, discussing the retrieval of

embedded resource images
:

It is possible to add your own video to a Revit ribbon button tool tip, and I’ve found a way to achieve this.

Video running in a Revit ribbon item tool tip

This can be achieved using the undocumented AdWindows.dll and UIFramework.dll assemblies located in the Revit program folder.

They provide many interesting classes, as Rudolf Honke already pointed out in his examples using

UI Automation
.

There is a RibbonToolTip class in the AdWindows.dll assembly.
The class provides a property named ExpandedVideo.
The next step is to find a class which can contain ToolTip property.
This class is Autodesk.Windows.RibbonItem.

So, the idea is to find the correct RibbonItem in the ribbon control and set RibbonToolTip to it.

But here there is the trouble.
We can create a PushButton on a Panel using Application.CreatePanel().AddItem(RevitItem) to obtain a Autodesk.Revit.UI.RibbonItem.
But we need Autodesk.Windows.RibbonItem.

There are several ways.

The first one – use RevitControl class and iterate all tabs, panels and buttons and find button by name.

We can get RevitControl instance using static property RibbonControl UIFramework.RevitRibbonControl class.

RibbonControl contains exactly Autodesk.Windows.RibbonItem items not a Autodesk.Revit.UI.RibbonItem.
It’s look like we need.

Here is the code implementing this:


  public Autodesk.Windows.RibbonItem GetRibbonItem(
    RibbonItem item )
  {
    RibbonControl ribbonControl
      = RevitRibbonControl.RibbonControl;
 
    foreach( var tab in ribbonControl.Tabs )
    {
      foreach( var panel in tab.Panels )
      {
        foreach( var ribbonItem
          in panel.Source.Items )
        {
          if( ribbonItem.AutomationName
            == item.Name )
          {
            return ribbonItem as
              Autodesk.Windows.RibbonItem;
          }
        }
      }
    }
    return null;
  }

But there is a second way.
The Autodesk.Revit.UI.RibbonItem class has an internal method getRibbonItem which returns Autodesk.Windows.RibbonItem. Interesting.
Try to use this method.
The reflection helps us.

Here is the code:


  public Autodesk.Windows.RibbonItem GetRibbonItem(
    RibbonItem item )
  {
    Type itemType = item.GetType();
 
    var mi = itemType.GetMethod( "getRibbonItem",
      BindingFlags.NonPublic | BindingFlags.Instance );
 
    var windowRibbonItem = mi.Invoke( item, null );
 
    return windowRibbonItem
      as Autodesk.Windows.RibbonItem;
  }

So, after we get a Autodesk.Windows.RibbonItem we can set RibbonToolTip to it.

For example like this:


  RibbonToolTip toolTip1 = new RibbonToolTip()
  {
    Title = "This is important button1",
    ExpandedContent =
@"Here you can see swf video from local file. 
The file path is C:/Program Files
/Autodesk/Revit Structure 2013/Program/videos
/GUID-053F3A19-7EFF-48D5-A0FA-AF0C2CC4BD9D-low.swf",       
    ExpandedVideo = new Uri( "C:/Program Files"
      + "/Autodesk/Revit Structure 2013/Program/videos"
      + "/GUID-053F3A19-7EFF-48D5-A0FA"
      + "-AF0C2CC4BD9D-low.swf" ),
    ExpandedImage = BitmapSourceConverter
      .ConvertFromImage( Resources.logoITC_16 )
  };

PROFIT!!!

Also there is a third way to get a Autodesk.Windows.RibbonItem.
Create a tab, panel and button directly via RevitControl class.
But I didn’t find how to set IExtenalCommand to a button.

RevitToolTip.ExpandedVideo supports SWF video.
Also I tried a GIF image.
The image was shown but didn’t animate.
Also I tried to set Internet URL.
On my computer it doesn’t work.
Maybe it doesn’t work via proxy, or maybe access is denied on video in the internet.
Please try and tell me.

To wrap this up, here is the
full source code of
my solution with test projects displaying video tool tip buttons for both Revit 2012 and 2013.

You may need to re-reference the Revit assemblies to compile them.

The first button loads a video from Revit Structure 201XProgramvideos.
If you have not installed RST you won’t see the video on the first button.
The second button loads a video from the internet, and the third button loads one from the embedded resources.
So everyone should be able to see the video on the Button3.

Hope this information is useful for you.

Many thanks to Victor for exploring and explaining this exciting possibility!

Adjusting Beam Cutback

By the way, here is a yet another topic that I wanted to address for a long time, and now Mikako beat me to it: the FamilyInstance ExtensionUtility property allows you to control the joining, cutback and extension behaviour of beams, columns, girders etc.
Mikako shows how in her discussion and real-world sample on

adjusting cutback programmatically
.

Girders with cutback and miter joins


Comments

9 responses to “Video Animated Ribbon Item Tooltip”

  1. Hi all,
    since AutoCAD and Revit share some sort of AdWindows.dll, someone could test this with Acad…
    Regards,
    Rudolf

  2. Dear Rudolf,
    As you know all too well: “immer der, der fragt” :-)
    I bet you were waiting for that answer :-)
    Cheers, Jeremy.

  3. Hi Jeremy,
    I think that this could be a new topic for Kean since he already has posted Ribbon and ToolTip related stuff.
    No, not me. Nooonono.
    ;-)
    I’m back from holiday this monday.
    I had thought about converting the Pimp-my-Revit-Or-AutoCAD code into an app, with the option to save UI colour schemes as XML files, but after all I think there is no market for this tool.
    Bye,
    Rudolf

  4. Hi, every one.
    Ich würde Ihnen helfen, das gleiche in AutoCad machen, aber ich niemals angelegt Add-Ins auf sie. :-)
    Have a nice day,
    Victor

  5. Hi Victor,
    in the Pimp-My-Revit-Or-AutoCAD posting you can see a code snippet for an AutoCAD plugin.
    In fact, you need to include the correct AutoCAD.NET dlls, then complile your plugin dll and load it into AutoCAD using netload.
    Hope this helps you with starting.
    Best regards,
    Rudolf

  6. Hi, Rudolf.
    Thanks a lot, but it was a joke :-) I don’t need to work with AutoCad and don’t want to write any add-ins.
    Sorry. I think if you need tooltip video in AutoCad you can implement it yourself easily regarding to my sample.
    Regards,
    Victor.

  7. Hi Victor,
    I forwarded it to Kean, so perhaps he may adjust it to the AutoCAD environment and blog about it.
    Cheers,
    Rudolf

  8. Hi Jeremy,
    Great tip! We had been wondering how to embed flash into the tooltips.
    Cheers,
    Steve

  9. Dear Steve,
    Good for you, so you are in luck, good karma.
    Thank you for the appreciation, which should all be directed to Victor.
    Cheers, Jeremy.

Leave a Reply to Victor ChekalinCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading