<?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 Trouble with getting families from specific category element in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/trouble-with-getting-families-from-specific-category-element/m-p/5789090#M70791</link>
    <description>&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been looking for ways to get the families who are in specific category, but in some categories, my code don't shows me some families.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my code for looking Families in Categories, I hope you will support me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;int iViewID = Convert.ToInt32(lbView.Text);
ElementId id = new ElementId(iViewID);

int iCategory = Convert.ToInt32(cmbCategory.SelectedValue.ToString());
ElementId catID = new ElementId(iCategory);


List&amp;lt;string&amp;gt; lstFamily = new List&amp;lt;string&amp;gt;();
List&amp;lt;string&amp;gt; lstFamilyType = new List&amp;lt;string&amp;gt;();



Dictionary&amp;lt;string, List&amp;lt;FamilySymbol&amp;gt;&amp;gt; FamilyTypes = new FilteredElementCollector(docM)
  .WherePasses(new ElementClassFilter(typeof(FamilySymbol)))
  .OfCategoryId(catID)
  .Cast&amp;lt;FamilySymbol&amp;gt;()
  .GroupBy(e3 =&amp;gt; e3.Family.Name)
  .ToDictionary(e3 =&amp;gt; e3.Key, e3 =&amp;gt; e3.ToList());



            
foreach (KeyValuePair&amp;lt;string, List&amp;lt;FamilySymbol&amp;gt;&amp;gt; entry in FamilyTypes)
{
	lstFamily.Add(entry.Key);
                
	foreach (FamilySymbol item in entry.Value)
	{
		Debug.Print(item.Name);
		lstFamilyType.Add(item.Name);
	}
}

            
           
cmbFamily.DataSource = lstFamily;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;</description>
    <pubDate>Wed, 26 Aug 2015 16:04:10 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-08-26T16:04:10Z</dc:date>
    <item>
      <title>Trouble with getting families from specific category element</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/trouble-with-getting-families-from-specific-category-element/m-p/5789090#M70791</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been looking for ways to get the families who are in specific category, but in some categories, my code don't shows me some families.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my code for looking Families in Categories, I hope you will support me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;int iViewID = Convert.ToInt32(lbView.Text);
ElementId id = new ElementId(iViewID);

int iCategory = Convert.ToInt32(cmbCategory.SelectedValue.ToString());
ElementId catID = new ElementId(iCategory);


List&amp;lt;string&amp;gt; lstFamily = new List&amp;lt;string&amp;gt;();
List&amp;lt;string&amp;gt; lstFamilyType = new List&amp;lt;string&amp;gt;();



Dictionary&amp;lt;string, List&amp;lt;FamilySymbol&amp;gt;&amp;gt; FamilyTypes = new FilteredElementCollector(docM)
  .WherePasses(new ElementClassFilter(typeof(FamilySymbol)))
  .OfCategoryId(catID)
  .Cast&amp;lt;FamilySymbol&amp;gt;()
  .GroupBy(e3 =&amp;gt; e3.Family.Name)
  .ToDictionary(e3 =&amp;gt; e3.Key, e3 =&amp;gt; e3.ToList());



            
foreach (KeyValuePair&amp;lt;string, List&amp;lt;FamilySymbol&amp;gt;&amp;gt; entry in FamilyTypes)
{
	lstFamily.Add(entry.Key);
                
	foreach (FamilySymbol item in entry.Value)
	{
		Debug.Print(item.Name);
		lstFamilyType.Add(item.Name);
	}
}

            
           
cmbFamily.DataSource = lstFamily;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2015 16:04:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/trouble-with-getting-families-from-specific-category-element/m-p/5789090#M70791</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-08-26T16:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with getting families from specific category element</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/trouble-with-getting-families-from-specific-category-element/m-p/5790782#M70792</link>
      <description>&lt;P&gt;Dear Carlos,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, your code is too long for my poor human brain to grok in detail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, there used to be one problematic aspect when querying a family for its category.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Family.Category property often does not return what you would expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case, you can&amp;nbsp;grab the first type (also called symbol) from it and ask that for its category instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh, and there is also a FamilyCategory property that you can use. That was introduced&amp;nbsp;later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are two sample&amp;nbsp;code snippets&amp;nbsp;from the ADN training labs,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/AdnRevitApiLabsXtra" target="_blank"&gt;https://github.com/jeremytammik/AdnRevitApiLabsXtra&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/AdnRevitApiLabsXtra/blob/master/XtraCs/Labs2.cs:" target="_blank"&gt;https://github.com/jeremytammik/AdnRevitApiLabsXtra/blob/master/XtraCs/Labs2.cs:&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;          // The element category is not implemented for all classes,
          // and may return null; for Family elements, one can sometimes
          // use the FamilyCategory property instead.

          s = string.Empty;

          if( null != e.Category )
          {
            s = e.Category.Name;
          }
          if( 0 == s.Length &amp;amp;&amp;amp; e is Family &amp;amp;&amp;amp; null != ( (Family) e ).FamilyCategory )
          {
            s = ( (Family) e ).FamilyCategory.Name;
          }
          if( 0 == s.Length )
          {
            s = "?";
          }&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/AdnRevitApiLabsXtra/blob/master/XtraCs/Labs3.cs:" target="_blank"&gt;https://github.com/jeremytammik/AdnRevitApiLabsXtra/blob/master/XtraCs/Labs3.cs:&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;      foreach( Family f in families )
      {
        // Get its category name; notice that the Category property is not
        // implemented for the Family class; use FamilyCategory instead;
        // notice that that is also not always implemented; in that case,
        // use the workaround demonstrated below, looking at the contained
        // family symbols' category:

        a.Add( string.Format( "Name={0}; Category={1}; FamilyCategory={2}",
          f.Name,
          ( ( null == f.Category ) ? "?" : f.Category.Name ),
          ( ( null == f.FamilyCategory ) ? "?" : f.FamilyCategory.Name ) ) );
      }
      #endregion // 3.1.a

      string msg = "{0} standard familie{1} are loaded in this model{2}";
      LabUtils.InfoMsg( msg, a );

      // Loop through the collection of families, and now look at
      // the child symbols (types) as well. These symbols can be
      // used to determine the family category.

      foreach( Family f in families )
      {
        string catName;
        bool first = true;

        // Loop all contained symbols (types):

        //foreach( FamilySymbol s in f.Symbols ) // 2014
        foreach( ElementId id in f.GetFamilySymbolIds() ) // 2015
        {
          FamilySymbol s = doc.GetElement( id ) as FamilySymbol;

          // you can determine the family category from its first symbol.

          if( first )
          {
            first = false;

            #region 3.1.b Retrieve category name of first family symbol:
            catName = s.Category.Name;
            #endregion // 3.1.b

            msg = "Family: Name=" + f.Name
              + "; Id=" + f.Id.IntegerValue.ToString()
              + "; Category=" + catName
              + "\r\nContains Types:";
          }
          msg += "\r\n    " + s.Name + "; Id=" + s.Id.IntegerValue.ToString();
        }

        // Show the symbols for this family and allow user to proceed
        // to the next family (OK) or cancel (Cancel)

        msg += "\r\nContinue?";
        if( !LabUtils.QuestionMsg( msg ) )
        {
          break;
        }
      }
&lt;/PRE&gt;
&lt;P&gt;I hope this helps.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2015 08:01:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/trouble-with-getting-families-from-specific-category-element/m-p/5790782#M70792</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2015-08-27T08:01:38Z</dc:date>
    </item>
  </channel>
</rss>

