-1

A few years ago, I was seeking a way to convert a list of elements into the current Selection (to use for "Copy To Level" or "Copy To Current View". My particular situation is post-program from a "Smart Filter" that allows the user to select multiple family names/types, not just "Structural Framing (girder)" as in Revit's built in filter.

The solution HAD BEEN:

SelElementSet SelSet = uiDoc.Selection.Elements;
SelSet.Add(Element1);
SelSet.Remove(Element2);

The problem is, this no longer seems to be working in Revit 2016 (+). Running the code with these lines now causes a program ending error:

"Revit encountered a System.MissingMethodException: Autodesk.Revit.UI.Selection.SelElementSet Autodesk.Revit.UI.Selection.Selection.get_Elements();" (I assume the line "SelElementSet SelSet = uiDoc.Selection.Elements" invoked .get_Elements)

I am able (at the start of my program) to obtain the current selection using

Selection All_Guys = uiDoc.Selection;

and from this I can convert everything to Ilist or List etc., based on using Tree nodes to remove particular categories/family names/family types. But then I need to be able to convert this all back to the current selection (hopefully using SelSet.Remove(Element2) for the elements that do not match the filtering), and every time I use SelElementSet, I get the program ending error above.

Note that in September, 2014 I asked a SIMILAR question. I know there are powerful arbiters on this site that are itching to mark questions as already answered -- this goes under a category "previous answer no longer works". Please read the question more carefully and don't have it thrown out just because you have the power.

Servy
  • 202,030
  • 26
  • 332
  • 449

1 Answers1

1

I have discovered that this is because SelElementSet was removed for Revit 2015 and beyond, and has been replaced with the following (type of) structure. In my example, I clear the selection and add specified elements, but I could also have ....elementids.Remove(One_Element) from another collection of elements:

if (SmartCopyLoad.ResetSelection)
{
    ICollection<ElementId> elementIds = uiDoc.Selection.GetElementIds();
    elementIds.Clear();
    foreach (Element One_Element in SmartCopy.MatchingElements) { elementIds.Add(One_Element.Id); }
    uiDoc.Selection.SetElementIds(elementIds);

    return Autodesk.Revit.UI.Result.Succeeded;
}

The result of this is the specified elements as a collection (as SelElementSet used to allow).

Note also that a major part of the problem was using old References. My years old code still referenced RevitAPI from 2014, which allowed SelElementSet, but wouldn't work in Revit2016. A word of warning to others: use older references only if necessary for programs running in the older software. Since we are only using 2015 and beyond, I can use the newer references.