How am I supposed to use ElementId

I ran into several methods now that return ElementId. My current one is trying to get filters from view templates. I used GetOrderedFilters and it returns ElementId. When I use RevitLookup and click on the value, which says “List” it gives me ParameterFilterElement where I can see all the values I would expect form the filters.

However when I try to get any of the info I get an AttributeError: ‘ElementId’ object has no attribute ‘Name’.

When I check out the ElementId class I don’t see anything about how I’m supposed to get the actual element from it. I’m I missing something here? What is the purpose of these methods returning ElementId?

ElementIds don’t have names, they are just a string of numbers. Whenever you have an ElementID and you want to get the actual element associated with it, you just have to call document.GetElement() like this:

import pyrevit

doc = pyrevit.revit.doc
element = doc.GetElement(YOUR ELEMENT ID)
Name = element.Name

Once you have the actual element, you can access all the associated Properties and Methods from there.


When I try to get categories this way I only get None as a result.

Getting the categories from a document is a little different. The way I get those is like this:

doc = revit.doc

allCategories = doc.Settings.Categories
usefulCategories = []

for c in allCategories:
    if c.AllowsBoundParameters:
        print c.Name

The “AllowsBoundParameters” property filters out so you only see categories that allow Project Parameters. You can skip that part, but you’ll get a bunch of categories that you probably won’t need.

I’m not trying to get all categories. Just the ones provided from GetCategories from filters which provides the elementId. As far as I know the only way to get a filter’s categories is using this method which returns elementId which I can’t seem to use with GetElement when it comes to categories.

This isn’t my final code, I’m just testing stuff out right now:

for f in filterList:
    categoriesId = f.GetCategories()
    print("Cat IDs :")
    categories = []
    for cI in categoriesId:
        for c in categories:
            print("Categories are: " + str(c))
        print("No Categories?!?!")

Oh I see, sorry for the confusion.

I just tried this. Rather than using doc.GetElement() on the category Ids that come out of the GetCategories(), I loop through the list of categories and try to match the ids.

doc = revit.doc

allCategories = doc.Settings.Categories

filters = DB.FilteredElementCollector(doc).OfClass(DB.ParameterFilterElement).ToElements()

for filter in filters:
    catIds = filter.GetCategories()
    if len(catIds) > 0:
        print "###{}###".format(filter.Name)
        print "### Categories ###"
        for id in catIds:
            for cat in allCategories:
                if cat.Id == id:
                    print cat.Name
1 Like