get family type revit api

public Result Execute( 
  ExternalCommandData commandData,
  ref string message,
  ElementSet elements )
{
  UIApplication uiapp = commandData.Application;
  Document doc = uiapp.ActiveUIDocument.Document;
 
  Stopwatch sw = Stopwatch.StartNew();
 
  XElement xmlFamilyInstances = new XElement( 
    "Family_Inventory" );
 
  // retrieve all families. 
  // use the ElementClassFilter shortcut 
  // and filter all "Family" elements.
 
  FilteredElementCollector families 
    = new FilteredElementCollector( doc );
 
  families.OfClass( typeof( Family ) );
 
  int nFamily = 0;
  int nSymbol = 0;
  int nInstance= 0;
 
  foreach( Family family in families )
  {
    ++nFamily;
 
    // XML: Start by adding the Family element
 
    XElement temp = new XElement( 
      "FamilyName", family.Name );
 
    // use the FamilySymbolFilter for each Family
 
    FamilySymbolFilter filterFamSym 
      = new FamilySymbolFilter( family.Id );
 
    FilteredElementCollector famSymbols 
      = new FilteredElementCollector( doc );
 
    famSymbols.WherePasses( filterFamSym );
 
    foreach( FamilySymbol famSymbol in famSymbols )
    {
      ++nSymbol;
 
      FamilyInstanceFilter filterFamilyInst 
        = new FamilyInstanceFilter( 
          doc, famSymbol.Id );
 
      FilteredElementCollector collectorFamInstances 
        = new FilteredElementCollector( 
          doc, doc.ActiveView.Id );
 
      IEnumerable<FamilyInstance> famInstances 
        = collectorFamInstances
          .WherePasses( filterFamilyInst )
          .OfType<FamilyInstance>();
 
      int nInstanceCount 
        = famInstances.Count<FamilyInstance>();
 
      nInstance += nInstanceCount;
 
      temp.Add( new XElement( 
        "SymbolName", 
        famSymbol.Name,
        from fi in famInstances
          select new XElement( 
            "Instance", 
            fi.Id.ToString(),
            new XElement( "Type", 
              fi.GetType().ToString() ),
            new XElement( "Position", 
              LocationString( fi ) ) ) ) );
    }
    xmlFamilyInstances.Add( temp );
  }
 
  // Create the XML report document
 
  XDocument xmldoc =
    new XDocument(
        new XDeclaration( "1.0", "utf-8", "yes" ),
        new XComment( 
          "Current Family Inventory of Revit project: "
          + doc.PathName ),
        xmlFamilyInstances );
 
  string fileName = "C:/FamilyInventory.xml";
  xmldoc.Save( fileName );
 
  Util.ShowElapsedTime( sw,
    "Linq Example 3 XML Report",
    string.Format( "{0} families with {1} symbols and {2} instances",
      nFamily, nSymbol, nInstance ),
    string.Empty );
 
  // We can use Internet Explorer or whatever 
  // your favorite XML viewer is...
  Process.Start(
    "C:/Program Files/Internet Explorer/iexplore.exe", 
    fileName);
 
  // Here is one that is free and is a little more 
  // robust than Internet Explorer. If interested, 
  // download from here: 
  // http://download.cnet.com/XML-Marker/3000-7241_4-10202365.html
  //Process.Start( @"C:/Program Files (x86)/XML Marker/xmlmarker.exe", fileName );
 
  return Result.Succeeded;
}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source