Category.Name

Category.Name

sonicer
Collaborator Collaborator
2,526 Views
2 Replies
Message 1 of 3

Category.Name

sonicer
Collaborator
Collaborator

I am preparing add-in and using pick object filter element.

I found this code on help webpage

 

public bool AllowElement(Element element)
    {
        if (element.Category.Name == "Mass")
        {
            return true;
        }
        return false;
    }

But it does't work if you have Revit in other language.

it's not universal code for all developers.

my code is longer and used BuiltInCategory parameter

 

Category cat = doc.GetElement(e).Category;
bcat = (BuiltInCategory)cat.Id.IntegerValue;

 

 

 

 

 

0 Likes
Accepted solutions (2)
2,527 Views
2 Replies
Replies (2)
Message 2 of 3

BIM.Frankliang
Collaborator
Collaborator
Accepted solution

Dear Friend,

 

I usually use below method to avoid using name comparision

elem.Category.Id.IntegerValue == (int)(BuiltInCategory.XXX)

 

Best Regards

Frank Liang

0.png

 

Message 3 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution

Thank you both for your good advice!

 

I fully agree.

 

I always recommend to avoid using language dependent comparisons, both for language independence and (less importantly)  efficiency reasons.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes