Category by name in Python


I am trying to get the Category by entering the string name.
Like the Dynamo node Category.ByName
It used to work but now all of a sudden it does not…

The Code:

import clr
import Revit

CAT = Revit.Elements.Category.ByName("Electrical Fixtures")

the error i get:

Hi @MelleH ,

I usually use the pyrevit.revit.db.query.get_elements_by_categories function for this.

from pyrevit.revit import query, DB

elements  = query.get_elements_by_categories([DB.BuiltInCategory.OST_ElectricalFixtures])

I’m afraid pyrevit library doesn’t include a way to specify the category using the name; I had to build a dictionary that maps the names to the corresponding builtin category enumeration

1 Like

maybe this is what you are after?

from pyrevit.revit import query
cat_name= # string name or builtincat
elements  = query.get_category(cat_name)

Yes this is it Thanks!