需要传入一个 Options的对象 打开的方式
Options options = new Options();
options.ComputeReferences = true;确定是否计算对几何对象的引用
options.IncludeNonVisibleObjects = true;是否提取未设置为可见的元素几何对象
options.DetailLevel = ViewDetailLevel.Fine; 提取的几何图形的详细级别
/// <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;
}