Loading a rfa file into a document using LoadFamily() freezes Revit UI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have encountered a problem while using the Document.LoadFamily() api to load an rfa file into Revit 2019 and Revit 2020. The problem can cause the ribbon UI to freeze until manually moving the mouse to any ribbon button or just resizing the revit window. The problem occurs only when the rfa file is created by an old version of revit which means somehow the upgrade process freezes the revit ribbon UI.
Actually I can reproduce this problem by loading a family manually from the Revit UI. If you want to give a try, remember to move the mouse to the ribbon tabs after loading the rfa. The tab background won't change when the mouse enters which means the ribbon UI is frozen.
If I want to show a WPF window right after the rfa file was loaded. This problem can cause the content of the window not to be rendered because the UI thread was somewhere stuck. Resizing the WPF window can make the content rendered. One thing to mention that winform is not affected by this problem maybe because the gdi engine.
Actually this problem was first encountered on Revit 2016-2018, and I found an api(RibbonControlService.updateLayout()) in UIFrameworkServices.dll. I call this api right after the family was loaded, everything was fine. But it just doesn't work in Revit 2019 and Revit 2020.
Things I have already tried by not working:
- Use the Dispatcher to show the Window with a higher priority.
- Resize the window with code right after the window is loaded.
- Use the win32 api to resize the WPF window and the Revit main window.
- Set the QuickAccessBar to blow ribbon and then set it back wishing to cause the UI to update.
- RibbonControlService.updateLayout() as I have mentioned.
- ComponentManager.Ribbon.UpdateLayout().
I made a short demo to reproduce this problem. The button in the center of the TestWindow doesn't show up. Can anybody give a help?
[Transaction(TransactionMode.Manual)] public class LoadFamilyCommand : IExternalCommand { #region Interface Implementations public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var document = commandData.Application.ActiveUIDocument.Document; var ofd = new OpenFileDialog(); var result = ofd.ShowDialog(); if (result.HasValue && result.Value) { using (var transaction = new Transaction(document, "Load Family")) { transaction.Start(); document.LoadFamily(ofd.FileName); transaction.Commit(); } RibbonControlService.updateLayout(); new TestWindow().ShowDialog(); } return Result.Succeeded; } #endregion } public class TestWindow : Window { #region Constructors public TestWindow() { InitializeComponents(); } #endregion #region Others private void InitializeComponents() { var grid = new Grid(); var button = new Button { Content = new TextBlock {Text = "Click Me"}, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; grid.Children.Add(button); Content = grid; } #endregion }