filtered collection to selection

filtered collection to selection

Anonymous
Not applicable
621 Views
4 Replies
Message 1 of 5

filtered collection to selection

Anonymous
Not applicable

Can someone give me an example of passing a filtered collection to a selection. I have clear examples of each, bit I'm having trouble sorting out how to combine them. Thanks.

0 Likes
622 Views
4 Replies
Replies (4)
Message 2 of 5

BKSpurgeon
Collaborator
Collaborator

I myself am a noob, but please post the individual examples, then maybe I can help?

0 Likes
Message 3 of 5

ollikat
Collaborator
Collaborator

Hi

Do you mean how to get elements from the FilteredElementCollector to the active selection? That shouldn't be too complicated.

We have the following extension method for the Selection class:

 

public static void SetSelection(this Selection sel, IEnumerable<ElementId> ids)
{
  if (sel == null)
  {
    throw new ArgumentNullException("sel");
  }

   if (ids == null)
  {
    throw new ArgumentNullException("ids");
  }

  sel.SetElementIds(ids.ToList<ElementId>());
}

Where "Selection" is from Autodesk.Revit.UI.Selection namespace. The enumerable can be retreived using for example

FilteredElementCollector.ToElementIds().

 

Ah...almost forget to mention that the ToList<T>() method is a Linq extension method for the IEnumerable System.Linq namspace.

 

Hope this helps.

0 Likes
Message 4 of 5

Anonymous
Not applicable

Autodesk.Revit.UI.Selection.SelElementSet
selElements = uiDoc.Selection.Elements;

 

loop all items in filter

foreach

{

 

selElements.Insert( items);

}

 

uiDoc.Selection.Elements = selElements;

 

Thanks & Regards

Sanjay Pandey

 

0 Likes
Message 5 of 5

BKSpurgeon
Collaborator
Collaborator

Hi i don't understand your question even:

 

Perhaps this might help:

 

it filters a selection and places it in a collection (the reverse of what you are trying to do).......but you may still find it helpful:

 

http://through-the-interface.typepad.com/through_the_interface/2008/05/finding-all-the.html

0 Likes