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;
}