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


C# FilteredElementCollector.FirstOrDefault方法代码示例

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


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

示例1: f

        Result f(
            UIDocument uidoc,
            Document doc)
        {
            string message = string.Empty;

              // Extract all pipe system types

              var mepSystemTypes
            = new FilteredElementCollector( doc )
              .OfClass( typeof( PipingSystemType ) )
              .OfType<PipingSystemType>()
              .ToList();

              // Get the Domestic hot water type

              var domesticHotWaterSystemType =
            mepSystemTypes.FirstOrDefault(
              st => st.SystemClassification ==
            MEPSystemClassification.DomesticHotWater );

              if( domesticHotWaterSystemType == null )
              {
            message = "Could not found Domestic Hot Water System Type";
            return Result.Failed;
              }

              // Looking for the PipeType

              var pipeTypes =
            new FilteredElementCollector( doc )
              .OfClass( typeof( PipeType ) )
              .OfType<PipeType>()
              .ToList();

              // Get the first type from the collection

              var firstPipeType =
              pipeTypes.FirstOrDefault();

              if( firstPipeType == null )
              {
            message = "Could not found Pipe Type";
            return Result.Failed;
              }

              var level = uidoc.ActiveView.GenLevel;

              if( level == null )
              {
            message = "Wrong Active View";
            return Result.Failed;
              }

              var startPoint = XYZ.Zero;

              var endPoint = new XYZ( 100, 0, 0 );

              using( var t = new Transaction( doc ) )
              {
            t.Start( "Create pipe using Pipe.Create" );

            var pipe = Pipe.Create( doc,
              domesticHotWaterSystemType.Id,
              firstPipeType.Id,
              level.Id,
              startPoint,
              endPoint );

            t.Commit();
              }
              Debug.Print( message );
              return Result.Succeeded;
        }
开发者ID:JesseMom,项目名称:the_building_coder_samples,代码行数:74,代码来源:CmdRollingOffset.cs

示例2: RetrieveOrLoadCuttingSymbol

        /// <summary>
        /// Retrieve cutting symbol, 
        /// loading family if needed.
        /// </summary>
        static FamilySymbol RetrieveOrLoadCuttingSymbol(
            Document doc)
        {
            FilteredElementCollector a
              = new FilteredElementCollector( doc )
            .OfClass( typeof( Family ) );

              Family family = a.FirstOrDefault<Element>(
            e => e.Name.Equals( FamilyName ) )
              as Family;

              if( null == family )
              {
            // It is not present, so check for
            // the file to load it from:

            if( !File.Exists( FamilyPath ) )
            {
              ErrorMsg( string.Format(
            "Please ensure that the void cutter "
            + "family file '{0}' is present.",
            FamilyPath ) );

              return null;
            }

            // Load family from file:

            using( Transaction tx = new Transaction(
              doc ) )
            {
              tx.Start( "Load Family" );
              doc.LoadFamily( FamilyPath, out family );
              tx.Commit();
            }
              }

              FamilySymbol cuttingSymbol = null;

              foreach( FamilySymbol s in family.Symbols )
              {
            cuttingSymbol = s;
            break;
              }

              return cuttingSymbol;
        }
开发者ID:jeremytammik,项目名称:InstanceVoidCutTest,代码行数:51,代码来源:Command.cs


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