0

I'm working on an addin that copies the selected sheets and edits them in some ways. I get the selection by using ICollection<ElementId> selectedIds = uiDoc.Selection.GetElementIds();
This works perfectly fine when the project browser is docked, but for some reason it doesn't work when it's not docked.
Is there any way to access the selection in the undocked project browser? I tried using
DockablePane projectBrowser = new DockablePane(DockablePanes.BuiltInDockablePanes.ProjectBrowser);
but I can't find any member to acces the selection from there.

I made the following small test addin to demonstrate:

using System.Collections.Generic;
using System.Linq;

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;

namespace Test
{
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    public class Test : IExternalCommand
    {
        public Result Execute(
        ExternalCommandData commandData,
        ref string message,
        ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            Document doc = uiDoc.Document;

            ICollection<ElementId> selectedIds = uiDoc.Selection.GetElementIds();

            int count = selectedIds.Count();

            if (count != 0)
            {
                TaskDialog.Show("test", "Selection: " + count.ToString() + " elements.");
            }
            else
            {
                TaskDialog.Show("test", "No selection");
            }

            return Result.Succeeded;
        }
    }
}

In a docked project browser, it returns the number of elements that you've selected but when it's undocked, it doesn't work. Is it possible to access this selection otherwise?

Jan Buijs
  • 98
  • 1
  • 6

2 Answers2

0

I discussed this with the Revit development team, and they would like to take a closer look at the issue. Can you please provide a full minimal reproducible case? In this case, I imagine that no model is needed, just the complete add-in code and detailed step by step instructions to reproduce the issue. Thank you!

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
0

Another, later, answer from the development team: I do not think it is related to the fact that browser is docked or undocked. It is most likely related to the fact whether the browser is the active view (only then selection in the browser is saved). If one clicks in a graphical view (outside of docked browser) the selection is cleared. If one clicks inside the browser (docked or undocked) - the selection is restored to contain items selected in the browser.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Hey Jeremy. Yes I figured it was that. When the undocked project browser is active, you cannot click buttons on the ribbon. You have to click the graphical view first, but as you were saying, you will lose your selection in doing that. The Project browser seems to behave differently than the Properties panel here, because buttons can still be clicked when that panel is the active view. – Jan Buijs Feb 06 '18 at 10:31
  • I wonder if you can access the 'greyed out' selection in the Project Browser when the graphical view is active. Is it possible to set the Project Browser panel as the active view programmaticaly? I noticed there is a `ViewType.ProjectBrowser` member. Maybe in doing that I can retrieve the selection – Jan Buijs Feb 06 '18 at 10:34
  • I believe you can set the project browser to be the active view via the `UIDocument` `ActiveView` property, c.f. http://www.revitapidocs.com/2018.1/b6adb74b-39af-9213-c37b-f54db76b75a3.htm – Jeremy Tammik Feb 07 '18 at 11:47
  • When I try that doing `uiDoc.ActiveView = new FilteredElementCollector(doc).OfClass(typeof(View)).Cast().Where(q => q.ViewType == ViewType.ProjectBrowser).First();` it gives me the exception "Cannot make an internal view active". I guess this is a dead end and I'll have to let the user select the sheets from a list in a window. Thanks for the help – Jan Buijs Feb 07 '18 at 16:34