Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.

Revit API Forum

Reply
Post 1 of 9
Accepted Solution

collect all room in leve xx

116 Views, 8 Replies
03-10-2017 04:36 AM

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.

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:

 

  • Elimination of ToList()
  • Elimination of New List<>()
  • Elimination of doc.GetElement()

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

 

Re: collect all room in leve xx

03-10-2017 06:43 AM in reply to: sonicer

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));
        }
once downhill, once uphill, but always on foot.
Post 3 of 9

Re: collect all room in leve xx

03-10-2017 09:52 AM in reply to: MarryTookMyCoffe

sorry don't work..

it does!nt know "Where.()..."and new List<room>

Post 4 of 9

Re: collect all room in leve xx

03-10-2017 10:20 AM in reply to: sonicer

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:

 

  • Elimination of ToList()
  • Elimination of New List<>()
  • Elimination of doc.GetElement()

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

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Post 5 of 9

Re: collect all room in leve xx

03-10-2017 02:10 PM in reply to: jeremytammik

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.

Re: collect all room in leve xx

03-10-2017 03:20 PM in reply to: sonicer

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.

once downhill, once uphill, but always on foot.
Highlighted
Post 7 of 9

Re: collect all room in leve xx

03-11-2017 03:07 AM in reply to: MarryTookMyCoffe

thx ...much

 

this is some funny :D 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 ) 

 

Post 8 of 9

Re: collect all room in leve xx

03-11-2017 06:14 AM in reply to: sonicer
Post 9 of 9

Re: collect all room in leve xx

03-14-2017 01:43 PM in reply to: sonicer

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 Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post

Revit Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Revit helps you achieve greater speed, accuracy, and automation from concept to manufacturing.