Search code examples
c#revit-apipyrevit

Xceed AvalonDock - Revit MainWindow.FindFirstChild returns nul


I am an Architect relatively new to C#, I am trying to implement Ehsan Iran-Nejad's amazing PyRevit coloured tabs in my own toolbar.

https://github.com/eirannejad/pyRevit/blob/12ecea9096bb649e2b6f084ba82ba1284bc78667/extensions/pyRevitTools.extension/pyRevit.tab/Toggles.panel/toggles1.stack/Tab%20Coloring.smartbutton/script.py

https://github.com/eirannejad/pyRevit/blob/12ecea9096bb649e2b6f084ba82ba1284bc78667/extensions/pyRevitTools.extension/pyRevit.tab/Toggles.panel/toggles1.stack/Tab%20Coloring.smartbutton/script.py

Unfortunately for me, this is returning null:

public static Xceed.Wpf.AvalonDock.DockingManager GetDockingManager(UIApplication uiapp)
{
    var wndRoot = (MainWindow)UIAppEventUtils.GetWindowRoot(uiapp);

    if (wndRoot != null)
    {
        return MainWindow.FindFirstChild<Xceed.Wpf.AvalonDock.DockingManager>(wndRoot);
    }
    return null;
}

Launched from the external command:

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class StartGroupingTabsExt : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        if(DocumentTabEventUtils.IsUpdatingDocumentTabs)
        {
            DocumentTabEventUtils.StopGroupingDocumentTabs();
        }
        else
        {
            DocumentTabEventUtils.StartGroupingDocumentTabs(commandData.Application);
        }        

        return Result.Succeeded;
    }
}

I cannot see quite what is going wrong.


Solution

  • I've had something similar happening when I was building something like that. I had referenced the xceed.wpf.avalondock library from nuget and that was what caused it. Maybe you did the same thing? If I instead referenced the dll that's in the Revit installation folder, it worked without a problem.