Revit 2013:我在哪里可以获得T墙连接?

时间:2013-07-02 19:23:33

标签: c# revit revit-api

我正在尝试从Revit中的给定墙中获取所有连接,但我在网上找到的所有资源都无法正常工作。

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

  

将所有元素加入到此元素位置的末尾

我还尝试了SDK显示的ElementIntersectsSolidFilter,但它返回了0个交叉点。

Wall joins

1 个答案:

答案 0 :(得分:1)

尝试反向工作并获得与主墙相匹配的墙的所有目标,以匹配主墙的元素ID。

虽然这是一个看似缓慢的过程,但你可以做一次并存储,如果这是一个经常重复的情况。

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

/// <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;
}