Questions about ElementIntersectsSolidFIlter

Questions about ElementIntersectsSolidFIlter

GZ1178
Participant Participant
2,568 Views
2 Replies
Message 1 of 3

Questions about ElementIntersectsSolidFIlter

GZ1178
Participant
Participant

Hello,

 

I once used ElementIntersectsSolid filter to find elements intersecting with a given solid,  but the instances belonging to Site Family cannot be obtained by the filter. Could anyone please do me a favor to tell me 1、Why such situation occurs and 2、How to use the filter to get instances of Site? 

 

Thank you so much!

 

P.s The code is shown below:

[Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class SolidIntersectElementTest : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //select a floor
            Document doc = commandData.Application.ActiveUIDocument.Document;
            Element floor = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Floors).FirstElement();
            //get the upper face
            Options opt = new Options();
            opt.ComputeReferences = true;
            opt.View = doc.ActiveView;
            var geos = floor.get_Geometry(opt);
            PlanarFace refFace = null;
            foreach(GeometryObject geoElem in geos)
            {
                if(geoElem is Solid)
                {
                    Solid sld = geoElem as Solid;
                    if(sld.Faces.Size>0)
                    {
                        foreach(Face fa in sld.Faces)
                        {
                            if(fa is PlanarFace)
                            {
                                PlanarFace pfa = fa as PlanarFace;
                                if(pfa.FaceNormal.Z>0)
                                {
                                    refFace = pfa;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if(refFace!=null)
            {
                var faceCvrLoops = refFace.GetEdgesAsCurveLoops();
                //generate a solid
                Solid testSolid = GeometryCreationUtilities.CreateExtrusionGeometry(faceCvrLoops, new XYZ(0, 0, 1), 2000 / 304.8);
                //apply solid intersection result
                FilteredElementCollector sldIntersectColl = new FilteredElementCollector(doc).WhereElementIsNotElementType();
                ElementIntersectsSolidFilter filter = new ElementIntersectsSolidFilter(testSolid);
                List<Element> lstElemFound = sldIntersectColl.WherePasses(filter).ToElements().ToList();
                //show the element found
                string strElemNamesAndCateogries = "Element found:\n";
                foreach(Element elem in lstElemFound)
                {
                    if(!( elem is FamilyInstance))
                    {
                        strElemNamesAndCateogries += elem.Name + "(" + elem.Category.Name + ")\n";
                    }
                    else
                    {
                        FamilyInstance fi = elem as FamilyInstance;
                        strElemNamesAndCateogries += elem.Name + "(" + fi.Symbol.Family.Name + ")\n";
                    }
                    
                }
                System.Windows.Forms.MessageBox.Show(strElemNamesAndCateogries);
                return Result.Succeeded;
            }
            else
            {
                return Result.Failed;
            }
            
            //throw new NotImplementedException();
        }
    }
0 Likes
Accepted solutions (1)
2,569 Views
2 Replies
Replies (2)
Message 2 of 3

FAIR59
Advisor
Advisor
Accepted solution

the remark for the usage of an ElementIntersectsElementFilter states:

The target object is another element. The intersection is determined with the same logic used by Revit to determine if an interference exists during generation of an Interference Report. (This means that some combinations of elements will never be detected as intersecting by this filter, such as concrete members which are automatically joined at their intersections). Also, elements which have no solid geometry, such as Rebar, will never be detected as intersecting by this filter.

this are the categories for a interference report:

 

interference_categories.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

I suspect that the same categories are "in play" for an the ElementIntersectsSolidFilter.

 

To find Site-families I see 2 options:

 

1. use a BoundingBoxIntersectsFilter,

2. temporary clone the Site-families using a DirectShape defined with a category that an ElementIntersectsSolidFilter can find. (e.g. Generic Model)

 

workflow option 2

 

  • start TransactionGroup
  • start Transaction
  • foreach Site-family
    • clone the solids from the geometry
    • create DirectShape
    • DirectShape.AppendShape( clonedsolids)
    • store combination <directshape.Id, familyinstance.id> in a Dictionary
  •  commit Transaction.
  • find elements passing the ElementIntersectsSolidFilter
  • rollback TransActionGroup
  • foreach elem in  lstElemFound
    • if (elem is DirectShape) retrieve  id of original familyinstance from stored Dictionary

 

 

 

Message 3 of 3

GZ1178
Participant
Participant

Dear FAIR59,

 

Thank you very much for answering my question and giving me the valuable suggestions. I really appreciate that!

0 Likes