Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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();
}
}
Solved! Go to Solution.