本文整理汇总了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;
}
示例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;
}