当前位置: 首页>>代码示例>>C#>>正文


C# FilteredElementCollector.UnionWith方法代码示例

本文整理汇总了C#中FilteredElementCollector.UnionWith方法的典型用法代码示例。如果您正苦于以下问题:C# FilteredElementCollector.UnionWith方法的具体用法?C# FilteredElementCollector.UnionWith怎么用?C# FilteredElementCollector.UnionWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FilteredElementCollector的用法示例。


在下文中一共展示了FilteredElementCollector.UnionWith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ListAllElements

    /// <summary>
    /// List all elements in Revit database.
    /// </summary>
    void ListAllElements()
    {
      // Create an output file:

      string filename = Path.Combine(
        Path.GetTempPath(), "RevitElements.txt");

      StreamWriter sw = new StreamWriter(filename);

      // The Revit API does not expect an application
      // ever to need to iterate over all elements.
      // To do so, we need to use a trick: ask for all
      // elements fulfilling a specific criteria and
      // unite them with all elements NOT fulfilling
      // the same criteria; an arbitrary criterion 
      // could be chosen:

      FilteredElementCollector collector
        = new FilteredElementCollector(_doc)
          .WhereElementIsElementType();

      FilteredElementCollector collector2
        = new FilteredElementCollector(_doc)
          .WhereElementIsNotElementType();

      collector.UnionWith(collector2);

      // Loop over the elements and list their data:

      string s, line;

      foreach (Element e in collector)
      {
        line = "Id=" + e.Id.IntegerValue.ToString(); // element id
        line += "; Class=" + e.GetType().Name; // element class, i.e. System.Type

        // The element category is not implemented for all classes,
        // and may return null; for family elements, one can sometimes
        // use the FamilyCategory property instead.

        s = string.Empty;

        if (null != e.Category)
        {
          s = e.Category.Name;
        }
        if (0 == s.Length && e is Family && null != ((Family)e).FamilyCategory)
        {
          s = ((Family)e).FamilyCategory.Name;
        }
        if (0 == s.Length)
        {
          s = "?";
        }
        line += "; Category=" + s;

        // The element Name property has a different meaning for different classes,
        // but is mostly implemented 'logically'. More precise info on elements
        // can be obtained in class-specific ways.

        line += "; Name=" + e.Name;

        //line += "; UniqueId=" + e.UniqueId;
        //line += "; Guid=" + GetGuid( e.UniqueId );

        sw.WriteLine(line);
      }
      sw.Close();

      TaskDialog.Show("List all elements",
        string.Format("Element list has been written to '{0}'.", filename));
    }
开发者ID:vnoves,项目名称:RevitTrainingMaterial,代码行数:75,代码来源:3_ElementFiltering.cs


注:本文中的FilteredElementCollector.UnionWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。