Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Reverse" element filter to collector

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
1008 Views, 2 Replies

"Reverse" element filter to collector

Hello all,

I'm trying to make an addin to automatically join geometry of intersecting walls and floors. My idea is to make 2 collectors for wall and floor. Then make a for-loop to iterate through all floor elements, find boundingbox of each element then apply boundingboxintersectsfilter to the wall collector, then join all intersecting wall with the floor. However, after the first iteration, the wall collector does not return to previous state with all the wall elements in the document, so I cannot apply the new element filter onto it. Is there a way to "reverse" the collector back in the for-loop?

Thanks.

 

Attached bellow is my code:

//col1 is wall collector; col2 is floor collector.

foreach (Element f in col2) { BoundingBoxXYZ a = f.get_BoundingBox(doc.ActiveView); Outline b = new Outline(a.Min, a.Max); BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(b,-0.5); IList<Element> ele = col1.WherePasses(filter).ToElements(); foreach (Element w in ele) { JoinGeometryUtils.JoinGeometry(doc, w, f); }
// code to return col1 to previous state. }

 

2 REPLIES 2
Message 2 of 3
FAIR59
in reply to: Anonymous

You can save the elementIds of the walls and use those as the basis for an FilterElementCollector repeatedly

 

ICollection<ElementId> wallIDs = col1.ToElementIds();
					
foreach (Element f in col2)
{
	BoundingBoxXYZ a = f.get_BoundingBox(doc.ActiveView);
        Outline b = new Outline(a.Min, a.Max);
        BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(b,-0.5);
//    IList<Element> ele = col1.WherePasses(filter).ToElements();
	IList<Element> ele = new FilteredElementCollector(doc,wallIDs)
		.WherePasses(filter).ToElements();

    foreach (Element w in ele)
    {
	    JoinGeometryUtils.JoinGeometry(doc, w, f);
    }
    // code to return col1 to previous state.
}
Message 3 of 3
Anonymous
in reply to: FAIR59

Thank you so much!!!!! That solved the problem.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report