Unselecting elements from selection set

Unselecting elements from selection set

Anonymous
Not applicable
1,784 Views
1 Reply
Message 1 of 2

Unselecting elements from selection set

Anonymous
Not applicable

I am trying to develop an environment where I can 'filter' user selections.  I don't seem to see anything in Revit that lets me filter a view such that some objects are editable or selectable and others are not.  If there is such a thing, then that might work for me.

 

As an alternative, what I would like to do is react to changes in the selection set and unselect things that I don't want selected.

(e.g. unselect anything that is not a room boundary).

 

I currently have a nonmodal dialog box that is showing me a list of selected elements, which is working fine, so I can list and identify the elements I want to deal with.

 

I have found some fairly old building coder posts referring to this

2009/02/selection-questions.html#1247912

which refers to the Elements property of a selection object.  I don't see this property, but I do see GetElementIds, and SetElementIds, etc.

 

I wonder if the object model has changes since 2009 and there is now a different way to do this, or if I am somehow looking at the wrong objects.

 

Does anyone have a sample of how to remove an object from the current selection?

 

Thanks in advance...

 

Abba Lustgarten

0 Likes
1,785 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

I figured this out soon after posting this question:

In case it is helpful for others, here is what I am doing so far - seems to work, although I am not sure if it the method I will eventually use.

 

There are some messy bits in this.  In this test, I am unselecting anything but room boundaries, which could probably be done in a more solid way.

The trick that I originally missed is that once the ids have been 'removed' from the element collection, this collection has to be 'reassigned' to the selection object with SetElementIds.

 

private void deselect_except_rmbound()
{
//MessageBox.Show("deselecting all but room boundaries");
List<Autodesk.Revit.DB.ElementId> to_delete = new List<ElementId>();
Autodesk.Revit.UI.Selection.Selection sel;
Document doc = thisuiapp.ActiveUIDocument.Document;
sel = thisuiapp.ActiveUIDocument.Selection;
ICollection<ElementId> ids = sel.GetElementIds();

 


foreach (ElementId id in ids)
{
Element el = doc.GetElement(id);

if (el.Category.Name == "<Room Separation>")
{
//MessageBox.Show(el.Category.Name + " will be left alone");
}
else
{
//MessageBox.Show(el.Category.Name + " will be removed");
to_delete.Add(id);
}

}

foreach (ElementId did in to_delete)
{
ids.Remove(did);
}

thisuiapp.ActiveUIDocument.Selection.SetElementIds(ids);
}

 

Incidentally, I have plugged this into an 'idling' handler so it gets called repeatedly.  I am not sure how much thrashing away it would do in a realistic situation.  If anyone sees anything too crazy in this, let me know.