Retrieve omniclass number from selected element

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I would like to know how to retrieve the omniclass number from a particular object with a shared parameter assocaited programmatically. I have checked the family of the object which has a omniclass number associated. I am also able to use schedule to retreive the omniclass number but when I use the following code, it always return null
Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;
BuiltInParameter _bipCode = BuiltInParameter.OMNICLASS_CODE;
BuiltInParameter _bipDesc = BuiltInParameter.OMNICLASS_DESCRIPTION;
UIApplication app = commandData.Application;
ElementId id = new ElementId(_bipCode);
ParameterValueProvider provider = new ParameterValueProvider(id);
FilterStringRuleEvaluator evaluator = new FilterStringGreater();
FilterRule rule = new FilterStringRule(provider,evaluator,"", false);
ElementParameterFilter filter = new ElementParameterFilter(rule);
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.WherePasses(filter);
ICollection<Element> allElements = collector.ToElements();
ICollection<Application.Record> filteredList = new List<Application.Record>();
foreach (Element element in allElements)
{
if (element.get_Parameter(_bipCode) != null)
{
omni_counter++;
omiclass = element.get_Parameter(_bipCode).AsString();
}
else
{
omiclass = null;
}
if (element.get_Parameter(_bipDesc) != null)
omiDesc = element.get_Parameter(_bipDesc).AsString();
else
omiDesc = null;
link = null;
foreach (Parameter p in element.Parameters)
{
if (p.Definition.Name.Equals("Item_no"))
{
link = p.AsString(); //crucial to use AsString() instead of ToString()
break;
}
}
if (link != null && link.Length > 0)
{
counter++;
if (omiclass != null) bi_counter++;
Thanks,