简体   繁体   中英

Selecting elements from undocked project browser

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?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM