本文整理汇总了C#中FilteredElementCollector.Where方法的典型用法代码示例。如果您正苦于以下问题:C# FilteredElementCollector.Where方法的具体用法?C# FilteredElementCollector.Where怎么用?C# FilteredElementCollector.Where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilteredElementCollector
的用法示例。
在下文中一共展示了FilteredElementCollector.Where方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PurgeGraphicStyles
/// <summary>
/// Purge all graphic styles whose name contains
/// the given substring. Watch out what you do!
/// If your substring is empty, this might delete
/// all graphic styles in the entire project!
/// </summary>
void PurgeGraphicStyles(
Document doc,
string name_substring)
{
FilteredElementCollector graphic_styles
= new FilteredElementCollector( doc )
.OfClass( typeof( GraphicsStyle ) );
int n1 = graphic_styles.Count<Element>();
IEnumerable<Element> red_line_styles
= graphic_styles.Where<Element>( e
=> e.Name.Contains( name_substring ) );
int n2 = red_line_styles.Count<Element>();
if( 0 < n2 )
{
using( Transaction tx = new Transaction( doc ) )
{
tx.Start( "Delete Line Styles" );
doc.Delete( red_line_styles
.Select<Element, ElementId>( e => e.Id )
.ToArray<ElementId>() );
tx.Commit();
TaskDialog.Show( "Purge line styles",
string.Format(
"Deleted {0} graphic style{1} named '*{2}*' "
+ "from {3} total graohic styles.",
n2, ( 1 == n2 ? "" : "s" ),
name_substring, n1 ) );
}
}
}
示例2: GetStairsOnLevel
/// <summary>
/// Retrieve all stairs on a given level.
/// </summary>
FilteredElementCollector GetStairsOnLevel(
Document doc,
Level level)
{
ElementId id = level.Id;
BuiltInCategory bic
= BuiltInCategory.OST_Stairs;
FilteredElementCollector collector
= new FilteredElementCollector( doc );
collector.OfCategory( bic );
// explicit iteration and manual
// checking of a property:
List<Element> stairs = new List<Element>();
foreach( Element e in collector )
{
if( e.LevelId.Equals( id ) )
{
stairs.Add( e );
}
}
// using LINQ:
IEnumerable<Element> stairsOnLevelLinq =
from e in collector
where e.LevelId.Equals( id )
select e;
// using an anonymous method:
IEnumerable<Element> stairsOnLevelAnon =
collector.Where<Element>( e
=> e.LevelId.Equals( id ) );
// using a parameter filter:
BuiltInParameter bip
= BuiltInParameter.STAIRS_BASE_LEVEL_PARAM;
ParameterValueProvider provider
= new ParameterValueProvider(
new ElementId( bip ) );
FilterNumericRuleEvaluator evaluator
= new FilterNumericEquals();
FilterRule rule = new FilterElementIdRule(
provider, evaluator, id );
ElementParameterFilter filter
= new ElementParameterFilter( rule );
return collector.WherePasses( filter );
}
示例3: GetFamilies
/// <summary>
/// Return all families whose name either matches or contains the given family name.
/// </summary>
/// <param name="doc">Revit document.</param>
/// <param name="family_name">Family name or substring to search for.</param>
/// <param name="search_for_substring">Search for substring or entire family name?</param>
/// <returns>Collection of families matching the search criteria.</returns>
public static IEnumerable<Family> GetFamilies(
Document doc,
string family_name,
bool search_for_substring)
{
FilteredElementCollector collector = new FilteredElementCollector( doc );
collector.OfClass( typeof( Family ) );
#if USE_LINQ
//
// using LINQ:
//
IEnumerable<Element> familiesByName =
from f in collector
where ( search_for_substring ? f.Name.Contains( family_name ) : f.Name.Equals( family_name ) )
select f;
return familiesByName.Cast<Family>();
#endif // USE_LINQ
//
// using an anonymous method to define a named method:
//
//Func<Element, bool> nameMatches = e
// => ( search_for_substring ? e.Name.Contains( family_name ) : e.Name.Equals( family_name ) );
//return collector.Where<Element>( nameMatches ).Cast<Family>();
//
// using an anonymous method:
//
return collector
.Where<Element>( e =>
( search_for_substring ? e.Name.Contains( family_name ) : e.Name.Equals( family_name ) ) )
.Cast<Family>();
}
示例4: Rooms
public static IEnumerable<Room> Rooms(this Document document)
{
var fc = new FilteredElementCollector(document).OfClass(typeof(SpatialElement)).OfType<Room>();
return fc.Where(elem => elem != null);
}
示例5: Execute
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
// Filtering for Room elements throws an exception:
// Input type is of an element type that exists in
// the API, but not in Revit's native object model.
// Try using Autodesk.Revit.DB.SpatialElement
// instead, and then postprocessing the results to
// find the elements of interest.
//FilteredElementCollector a
// = new FilteredElementCollector( doc )
// .OfClass( typeof( Room ) );
// Solution using SpatialElement and then
// checking for Room type
//FilteredElementCollector a
// = new FilteredElementCollector( doc )
// .OfClass( typeof( SpatialElement ) );
//foreach( SpatialElement e in a )
//{
// Room room = e as Room;
// if( null != room )
// {
// ListRoomData( room );
// }
//}
// Improvement suggested by
// Victor Chekalin using LINQ
// http://thebuildingcoder.typepad.com/blog/2011/11/accessing-room-data.html
// ?cid=6a00e553e168978833017c3690489f970b#comment-6a00e553e168978833017c3690489f970b
// --> version 2013.0.100.2
//FilteredElementCollector collector
// = new FilteredElementCollector( doc );
//var rooms = collector
// .OfClass( typeof( SpatialElement ) )
// .OfType<Room>();
//FilteredElementCollector collector
// = new FilteredElementCollector( doc );
//var rooms = collector
// .OfClass( typeof( SpatialElement ) )
// .OfType<Room>();
FilteredElementCollector collector
= new FilteredElementCollector( doc )
.OfClass( typeof( SpatialElement ) );
IEnumerable<Element> rooms = collector
.Where<Element>( e => e is Room );
foreach( Room room in rooms )
{
ListRoomData( room );
}
return Result.Succeeded;
}
示例6: GetModelExtents
/// <summary>
/// Return a bounding box enclosing all model
/// elements using only quick filters.
/// </summary>
BoundingBoxXYZ GetModelExtents( Document doc )
{
FilteredElementCollector quick_model_elements
= new FilteredElementCollector( doc )
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent();
IEnumerable<BoundingBoxXYZ> bbs = quick_model_elements
.Where<Element>( e => null != e.Category )
.Select<Element,BoundingBoxXYZ>( e
=> e.get_BoundingBox( null ) );
return bbs.Aggregate<BoundingBoxXYZ>( ( a, b )
=> { a.ExpandToContain( b ); return a; } );
}