How can I collect all rooms in level 01...a then do somethin with this rooms?
i used coolectelement filter....no idea how to get....have somebody complet source code....
I can do that in dynamo ...now I want do that in c# ....c# beginner programmer...
code for revit 2016 api or revit 2017 api.
thx.
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
you have problem because you can't collect Rooms, you need collect SpatialElement.
public List<Room> getRoomFromLevel(Document document, Level level) { List<Element> Rooms = new FilteredElementCollector(document).OfClass(typeof(SpatialElement)).WhereElementIsNotElementType().Where(room => room.GetType() == typeof(Room)).ToList(); return new List<Room>(Rooms.Where(room => document.GetElement(room.LevelId) == level).Select(r => r as Room)); }
Very good solution!
Thank you!
'Where' and 'List<>' come from the System.Collections.Generic namespace.
Here are some further small improvements:
return new FilteredElementCollector( doc ) .WhereElementIsNotElementType() .OfClass( typeof( SpatialElement ) ) .Where( e => e.GetType() == typeof( Room ) ) .Where( e => e.LevelId.IntegerValue.Equals( idLevel.IntegerValue ) ) .Cast<Room>();
More efficient because of:
You can see how to compile it in The Building Coder samples:
https://github.com/jeremytammik/the_building_coder_samples/compare/2017.0.132.7...2017.0.132.8
Cheers,
Jeremy
wou thx Tammik your code work for me....But I want know how to use the first code?I make some change
List<Element> Rooms = new FilteredElementCollector(doc).OfClass(typeof(SpatialElement)).WhereElementIsNotElementType().Where(room => room.GetType() == typeof(Room)).ToList();
List<Room> Rooms1 = new List<Room>(Rooms.Where(room => doc.GetElement(room.LevelId) == level).Select(r => r as Room));
I know the level 01 have id =355....why can I use 355 instead of "level"??? Or make some other mistake? Levelid is string, integer ??
In your code I inserted value 355 instead of idLevel.IntegerValue ...this work.
level.levelId is type ElementId and you can use integervalue if you what have (int) or toString and then you gonna have string.
I suggest using Jeremy code, don't focus much on code that I write in one minute.
by the way thanks jeremy for improving it. It look much better in one lane.
thx ...much
this is some funny 😄 its not element type and then is typ of spacial element and type of room....not so much logical.....
WhereElementIsNotElementType() .OfClass( typeof( SpatialElement ) ) .Where( e => e.GetType() == typeof( Room )
http://thebuildingcoder.typepad.com/blog/2010/08/filtering-for-a-nonnative-class.html
Look at the remarks on the ElementClassFilter Class:
http://www.revitapidocs.com/2017/4b7fb6d7-cb9c-d556-56fc-003a0b8a51b7.htm
I summarised this discussion on The Building Coder for legibility and future reference:
http://thebuildingcoder.typepad.com/blog/2017/03/events-uv-coordinates-and-rooms-on-level.html#6
Cheers,
Jeremy
Jeremy:
Can you please explain what is the variable e in your reply? It was not used in the example you corrected. Does it need to be defined as the selected element?
I see no variable `e` except within the LINQ query expressions, so I do not understand your question.
I realize the API has very likely been updated since this OP, but I find the addition of .OfCategory(BuiltinCategory.OST_Rooms) in lieu of the oftype filters.
Oh yes! Thank you for the pointer. OfCategory is much better, being a fast filter, rather than post-processing with .NET Where, which is not a filter at all, and hence much, much less performant.
Can't find what you're looking for? Ask the community or share your knowledge.