How can i list all the materials used in a particular project.??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I tried to list out all the family instances in a project and get materials used, volume and area of materials used....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
namespace param
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class instance : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Application app = uiApp.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;
ElementClassFilter FamilyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));
FilteredElementCollector FamilyInstanceCollector = new FilteredElementCollector(doc);
ICollection<Element> AllFamilyInstances = FamilyInstanceCollector.WherePasses(FamilyInstanceFilter).ToElements();
List<string> ParamLst = new List<string>();
FamilySymbol FmlySmbl;
Family Fmly;
string s = string.Empty;
foreach (FamilyInstance f in AllFamilyInstances)
{
FmlySmbl = f.Symbol;
Fmly = FmlySmbl.Family;
// Add Instance Parameter names to list
s += "\n" + f.Name + "\n";
s += f.Category.Name + "\n";
s += FmlySmbl.Name + "\n";
s += Fmly.Name + "\n";
ElementId elemId = f.Id;
ICollection<ElementId> materials = f.GetMaterialIds(false);
foreach (ElementId matId in materials)
{
Material material = doc.GetElement(matId) as Material;
s += "Materials = " + material.Name + "\n";
s += "Material Volume =" + f.GetMaterialVolume(matId) + "\n";
s += "Material Area = " + f.GetMaterialArea(matId, false) + "\n";
double volume = f.GetMaterialVolume(matId);
double area = f.GetMaterialArea(matId, false);
}
// Get FamilyInstance AnalyticalModel type
if (null != f.GetAnalyticalModel())
{
s += "FamilyInstance AnalyticalModel is : " + f.GetAnalyticalModel() + "\n";
}
// Get FamilyInstance host name
if (f.Host != null)
{
s += "FamilyInstance host name is : " + f.Host.Name + "\n";
}
foreach (ElementId materialId in f.GetMaterialIds(false))
{
Material material = f.Document.GetElement(materialId) as Material;
s += "FamilyInstance e material : " + material.Name + "\n";
}
// Get FamilyInstance structural type
s += "FamilyInstance structural type is : " + f.StructuralType + "\n";
// Get FamilyInstance structural usage
s += "FamilyInstance structural usage is : " + f.StructuralUsage + "\n";
// as an experiment, let's pick up some arbitrary parameters.
// comments - most of instance has this parameter
// (1) by BuiltInParameter.
Parameter param = f.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
if (param != null)
{
s += "Comments (by BuiltInParameter) = " + ParamaterToString(param) + "\n";
}
// (2) by name. (Mark - most of instance has this parameter.)
// if you use this method, it will language specific.
param = f.get_Parameter("Mark");
if (param != null)
{
s += "Mark (by Name) = " + ParamaterToString(param) + "\n";
}
param = f.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH);
if (param != null)
{
s += "Length =" + ParamaterToString(param) + "\n";
}
// the following should be in most of type parameter
//
param = f.get_Parameter(BuiltInParameter.ALTERNATE_UNITS);
if (param != null)
{
s += "Alternate Units = " + ParamaterToString(param) + "\n";
}
}
TaskDialog.Show("Revit", s);
return Result.Succeeded;
}
private static string ParamaterToString(Parameter P)
{
string val = "none";
if (P == null)
{
return val;
}
// to get to the parameter value, we need to pause it depending
// on its strage type
switch (P.StorageType)
{
case StorageType.Double:
double dVal = P.AsDouble();
val = dVal.ToString();
break;
case StorageType.Integer:
int iVal = P.AsInteger();
val = iVal.ToString();
break;
case StorageType.String:
string sVal = P.AsString();
val = sVal;
break;
case StorageType.ElementId:
ElementId idVal = P.AsElementId();
val = idVal.IntegerValue.ToString();
break;
case StorageType.None:
break;
default:
break;
}
return val;
}
}
}
lately i realised that walls or not included in the output, also handrails, stairs.. i attatched the building view.
what should i do to get all the family instances or elements ( which has materials ). ?
I want this data to automates Bill of Quantities...
Thanks in advance.