【问题标题】:REVIT API Filtering Elements by EdgesREVIT API 按边过滤元素
【发布时间】:2018-04-04 12:45:48
【问题描述】:

我必须从文档中的每个边缘检索端点,但是由于必须遍历每个元素,检索边缘的过程花费了太多时间。 我目前的做法是

FilteredElementCollector collector = new FilteredElementCollector(doc);
            collector.WherePasses(new LogicalOrFilter((new         ElementIsElementTypeFilter(false)), new ElementIsElementTypeFilter(true)));
            List<object> coordinatelist = new List<object>();
            for (int i = collector.ToElements().Count - 1; i > 0; i--)
                {
                Element element = collector.ToElements()[i];
                GeometryElement geo = element.get_Geometry(new Options());
                if (geo != null)
                {
                    for(int j = geo.Count()-1;j>=0;j--){
                    Solid geosolid = geo.ElementAt(j) as Solid;
                        if(geosolid != null)
                            {
                            for(int k = geosolid.Edges.Size - 1; k >= 0; k--)
                            {
                                Edge edge = geosolid.Edges.get_Item(k);
                                Curve edgecurve = edge.AsCurve();
                                FillDictionary(edgecurve, element);
                            }
                        }
                        else continue;
                    }
                }
                else continue;

            }

我无法按边缘过滤,因为 Edge 不是 Element 的子对象,而是 GeometryObject 的子对象

如何在不遍历每个元素的情况下获得边缘,或者如何加快流程?

【问题讨论】:

    标签: revit-api revit


    【解决方案1】:

    您可以从迭代中消除很多元素。

    为什么要迭代满足ElementIsElementTypeFilter( true ) 的元素?

    它们在项目中不存在;它们只是模板、类型、符号。项目模型空间中仅存在实例。

    此外,您在循环中调用ToElements,每次迭代。这是每次创建所有元素的新集合。这是对时间和空间的巨大浪费。

    根本不需要打电话ToElements!查看FindElement and Collector Optimisation 的讨论。

    您也可以消除许多其他元素。例如,您感兴趣的元素可能几乎肯定有一个有效的类别。

    The Building Coder 探索了Retrieve Model Elements or Visible 3D Elements 的几种不同方法。

    如果需要,您可以在 LINQ 子句中添加对非空心实体的检查和实体的提取,以使您的代码更短且更具可读性;但是,这可能不会对性能产生太大影响。

    这样的?

    void RetrieveEdges( 
      Document doc, 
      Dictionary<Curve, ElementId> curves )
    {
      FilteredElementCollector collector
        = new FilteredElementCollector( doc )
          .WhereElementIsNotElementType()
          .WhereElementIsViewIndependent();
    
      Options opt = new Options();
    
      foreach( Element el in collector )
      {
        if( null != el.Category )
        {
          GeometryElement geo = el.get_Geometry( opt );
          if( geo != null )
          {
            foreach( GeometryObject obj in geo )
            {
              Solid sol = obj as Solid;
              if( null!= sol )
              {
                foreach( Edge edge in sol.Edges )
                {
                  Curve edgecurve = edge.AsCurve();
                  curves.Add( edgecurve, el.Id );
                }
              }
            }
          }
        }
      }
    }
    

    【讨论】:

    • 谢谢,最近又捡到这个了,发现我只需要墙。 :D
    • 简单得多:-)
    【解决方案2】:

    如果您确实需要所有几何元素,避免一一检查它们的一种方法是实现custom exporter。这将为您提供 3D 视图中所有可见元素的所有几何图形,零麻烦。如果您只需要墙壁,请设置仅显示这些墙壁的合适 3D 视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 2020-08-18
      • 2011-09-26
      • 2020-11-14
      • 2015-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多