转载自 STLN——软件技术分享网
Revit中有些构件是需要基于面来放置,此时我们就需要获取元素的面。接下来对如何利用Revit API获取元素的所有面进行详细说明。
一、实现逻辑
- 根据打开方式获取元素的几何信息
- 从获取的几何信息中过滤出GeometryInstance
- 从GeometryInstance中过滤出solid、Face、Line等
二、具体代码
/// <summary>
/// 元素的所有面
/// </summary>
/// <param name="item">元素</param>
/// <param name="options">打开方式</param>
/// <returns>所有的面</returns>
public static List<Face> GetFaceByElement(this Element item, Options options)
{
List<Face> listFace = new List<Face>();
根据打开的方式得到几何信息
GeometryElement geometry = item.get_Geometry(options);
foreach (GeometryObject geomObj in geometry)
{
GeometryInstance geomInstance = geomObj as GeometryInstance;
if (geomInstance != null)
{
foreach (GeometryObject instObj in geomInstance.GetInstanceGeometry())
{
三维的实体
Solid instsolid = instObj as Solid;
if (instsolid == null || instsolid.Faces.Size == 0 || instsolid.Edges.Size == 0)
{
continue;
}
foreach (Face face in instsolid.Faces)
{
listFace.Add(face);
}
}
}
Solid solid = geomObj as Solid;
if (solid != null)
{
if (solid.Faces.Size == 0 || solid.Edges.Size == 0)
{
continue;
}
else
{
foreach (Face face in solid.Faces)
{
listFace.Add(face);
}
}
}
}
return listFace;
}