Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get OmniClass Number

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
chuong_do77UDA
849 Views, 5 Replies

How to get OmniClass Number

hi there,

Do we have any way to get the OmniClass Number in the Identity Data by using API?

For example : I have Engine Generators has OmniClass Number = "23.80.10.11.11.11". How can I get this value?

Thanks.

5 REPLIES 5
Message 2 of 6

Hi! Omniclass Number is a System Type Parameter. To get it for each element first you need to get Element's Type and then try to get the OMNICLASS_CODE parameter. If this particulat ElementType has it, then you can get its value. Here is the sample code:

foreach (Element element in elements)
{
    ElementType elementType = doc.GetElement(element.GetTypeId()) as ElementType;
    Parameter omniClassNumber = elementType.get_Parameter(BuiltInParameter.OMNICLASS_CODE);
    if (omniClassNumber != null)
    {
        string value = omniClassNumber.AsString();
        if (!string.IsNullOrEmpty(value))
        {
            Console.WriteLine(value);
        }
        else
        {
            Console.WriteLine("No Value");
        }
    }
    else
    {
        Console.WriteLine("Element does not have Omni Class Number Parameter");
    }
}

 


Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 3 of 6

Thanks for your answer. Base on your code it only gets OmniClass Number = "23.80.10.11" ( Electrical Generators)

 

It should be "23.80.10.11.11.11" of Engine Generators. Please review again and help. Thank you.

OmniClassNumber.png

Message 4 of 6

Hi! There is no problem to get Omni Class Number of any kind using the code I've provided you above. I've tested this code in Python and it works fine too.

architectbim_0-1683764705998.jpeg

Actually there is nothin to review, just simply use it 😃

If you don't see the last digits of the omniclass, they may simply not be printed. Or you may have made an inaccuracy somewhere. Either way, there is actually no other way to get this number. It is stored as a string parameter value. And to get it, you need the methods I mentioned above.


Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 5 of 6

hi there,

I am using FilteredElementCollector to filter elements.

 

filter = new BuiltInCategory[] {
BuiltInCategory.OST_ElectricalEquipment,
BuiltInCategory.OST_ElectricalFixtures,
BuiltInCategory.OST_LightingDevices,
BuiltInCategory.OST_LightingFixtures,
BuiltInCategory.OST_Wire, 
BuiltInCategory.OST_ElectricalCircuit,
BuiltInCategory.OST_WireMaterials,
BuiltInCategory.OST_WireInsulations,
BuiltInCategory.OST_WireTemperatureRatings,
BuiltInCategory.OST_ElecDistributionSys,
BuiltInCategory.OST_ElectricalVoltage,
BuiltInCategory.OST_MechanicalEquipment,
BuiltInCategory.OST_Levels,
};

Do you think the filter I miss anything?

Message 6 of 6

I'm not sure how this question relates to the omniclass number. I would advise you to accept solution for this question and create a new query in the forum if you have any new questions.


Maxim Stepannikov | Architect, BIM Manager, Instructor

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report