Retrieve omniclass number from selected element

Retrieve omniclass number from selected element

Anonymous
Not applicable
632 Views
1 Reply
Message 1 of 2

Retrieve omniclass number from selected element

Anonymous
Not applicable

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,

 

0 Likes
633 Views
1 Reply
Reply (1)
Message 2 of 2

Mustafa.Salaheldin
Collaborator
Collaborator

I used the same code and it returns values. !!! If you can provide sample projrct this may help to figure out what is wrong.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes