<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Sort Levels by Elevation in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5407923#M74942</link>
    <description>&lt;P&gt;public static IOrderedEnumerable&amp;lt;Level&amp;gt; FindAndSortLevels(Document doc)&lt;BR /&gt;{&lt;BR /&gt;return new FilteredElementCollector(doc)&lt;BR /&gt;.WherePasses(new ElementClassFilter(typeof(Level), false))&lt;BR /&gt;.Cast&amp;lt;Level&amp;gt;()&lt;BR /&gt;.OrderBy(e =&amp;gt; e.Elevation);&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Mon, 17 Nov 2014 10:30:41 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-11-17T10:30:41Z</dc:date>
    <item>
      <title>Sort Levels by Elevation</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5407203#M74940</link>
      <description>&lt;P&gt;How would I go about getting a collection of levels sorted by elevation? &amp;nbsp;From reading the info I've found so far I think that filtered element collector returns an Ienumerable and that can be sorted by using "OrderBy", then ToElementIds could be used to create the collection of element ids in the correct order. &amp;nbsp;Is that correct? &amp;nbsp;Below is some code I tried and didn't work. &amp;nbsp;Can someone please point me in the right direction?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, is an Icollection sortable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;UIDocument uiDoc = this.ActiveUIDocument;
Document doc = uiDoc.Document;


FilteredElementCollector levCollector = new FilteredElementCollector(doc);&lt;BR /&gt;
ICollection&amp;lt;Element&amp;gt; levelsCollection = levCollector.OfClass(typeof(Level)).OrderBy(lev =&amp;gt; lev.Elevation).ToElementIds();&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Nov 2014 20:14:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5407203#M74940</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-11-16T20:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Levels by Elevation</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5407251#M74941</link>
      <description>I didn't look at all the other stuff, but if you define an Element collection, you should fill it with Elements, not ElementIds.&lt;BR /&gt;&lt;BR /&gt;ICollection&amp;lt;Element&amp;gt;.......ToElementIds();</description>
      <pubDate>Sun, 16 Nov 2014 20:52:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5407251#M74941</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-11-16T20:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Levels by Elevation</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5407923#M74942</link>
      <description>&lt;P&gt;public static IOrderedEnumerable&amp;lt;Level&amp;gt; FindAndSortLevels(Document doc)&lt;BR /&gt;{&lt;BR /&gt;return new FilteredElementCollector(doc)&lt;BR /&gt;.WherePasses(new ElementClassFilter(typeof(Level), false))&lt;BR /&gt;.Cast&amp;lt;Level&amp;gt;()&lt;BR /&gt;.OrderBy(e =&amp;gt; e.Elevation);&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Mon, 17 Nov 2014 10:30:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5407923#M74942</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-11-17T10:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Levels by Elevation</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5413213#M74943</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can change&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ICollection&amp;lt;Element&amp;gt; levelsCollection = levCollector.OfClass(typeof(Level)).OrderBy(lev =&amp;gt; lev.Elevation).ToElementIds();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;Level&amp;gt; levelsCollection = levCollector.OfClass(typeof(Level)).OfType&amp;lt;Level&amp;gt;().OrderBy(lev =&amp;gt; lev.Elevation).ToList();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Return value can't be ICollection&amp;lt;Element&amp;gt; when you call .ToElementIds&lt;/P&gt;&lt;P&gt;2. OfClass() method will return a collection of Element, you can only order them by elevation after casting Element to Level, that's why I suggest using OfType&amp;lt;Level&amp;gt;()&lt;/P&gt;&lt;P&gt;3. OrderBy() method returns IOrderedEnumerable&amp;lt;T&amp;gt;, if you want to have index operator, i.e. list[i], you can call ToList() to let it return a List&amp;lt;T&amp;gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2014 06:32:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5413213#M74943</guid>
      <dc:creator>Aaron.Lu</dc:creator>
      <dc:date>2014-11-19T06:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Levels by Elevation</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5413927#M74944</link>
      <description>&lt;P&gt;Hey guys, thank you for all your cool suggestions!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I summarised the discussion and added my contribution to it on The Building Coder:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2014/11/webgl-goes-mobile-and-sorted-level-retrieval.html#3" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2014/11/webgl-goes-mobile-and-sorted-level-retrieval.html#3&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also added my code snippet suggestion to The Building Coder samples:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2014 12:11:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/sort-levels-by-elevation/m-p/5413927#M74944</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2014-11-19T12:11:01Z</dc:date>
    </item>
  </channel>
</rss>

