0

我正在尝试从 Revit 中的给定墙获取所有连接,但我在网络上找到的所有资源都不起作用。

LocationCurve.get_ElementsAtJoin(n)唯一返回一些,正如文档指出的那样:

获取连接到此元素位置末尾的所有元素

我也尝试了ElementIntersectsSolidFilterSDK 显示的,但它返回 0 个交叉点。

墙连接

4

1 回答 1

1

尝试反向工作并获得与主墙相匹配的主墙的所有末端。

虽然这是一个看似缓慢的过程,但如果它经常重复出现,您可以执行一次并存储。

以下代码给出了要点,并且确信它可以改进(并且未经测试)。

/// <summary>
/// Create a dictionary of adjoinging walls keyed on a particular wall ID.
/// </summary>
/// <param name="document">Tje Revit API Document</param>
/// <returns>A dictionary keyed on a wall id containing a collection of walls that adjoin the key id wall</returns>
public IDictionary<ElementId,ICollection<Wall>> GetAdjoiningWallsMap(Document document)
{
    IDictionary<ElementId, ICollection<Wall>> result = new Dictionary<ElementId, ICollection<Wall>>();

    FilteredElementCollector collector = new FilteredElementCollector(document);
    collector.OfClass(typeof(Wall));
    foreach (Wall wall in collector.Cast<Wall>())
    {
        IEnumerable<Element> joinedElements0 = GetAdjoiningElements(wall.Location as LocationCurve, wall.Id, 0);
        IEnumerable<Element> joinedElements1 = GetAdjoiningElements(wall.Location as LocationCurve, wall.Id, 1);
        result[wall.Id] = joinedElements0.Union(joinedElements1).OfType<Wall>().ToList();
    }
    return result;
}

private IEnumerable<Element> GetAdjoiningElements(LocationCurve locationCurve, ElementId wallId, Int32 index)
{
    IList<Element> result = new List<Element>();
    ElementArray a = locationCurve.get_ElementsAtJoin(index);
    foreach (Element element in a)
        if (element.Id != wallId)
            result.Add(element);
    return result;
}
于 2013-07-03T07:55:56.757 回答