get builtIncategory from elements

get builtIncategory from elements

Anonymous
Not applicable
22,940 Views
9 Replies
Message 1 of 10

get builtIncategory from elements

Anonymous
Not applicable

 

Hello

how get builtInCategory (OST_…) from the list of elements

Accepted solutions (1)
22,941 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

probably (im not shure) all cats we can get that:

foreach (var j in System.Enum.GetValues(typeof(BuiltInCategory)))


and later for current elements get OST

0 Likes
Message 3 of 10

jeremytammik
Autodesk
Autodesk

Use the Element.Category property on each element:

 

http://www.revitapidocs.com/2018.1/8990bd36-af08-fc99-496b-f94fcb056b21.htm

 

  element.Category.Id 

Returns the built-in category enum.

 

Please perform your own searches prior to asking further questions.



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

Message 4 of 10

Anonymous
Not applicable

Sorry , this my first code  in C#

 

please help continue my code..

 

var lst_= new List<string>();

foreach (var i in uidoc.Selection.GetElementIds())

lst_.Add(i.Category.Id); // at this place im try to get OST_...
0 Likes
Message 5 of 10

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Til,

 

Thank you, but no thank you.

 

If this is your first code, I welcome you to Revit API programming!

 

To get started with the Revit API, I suggest that you first of all take a look at the getting started material and work through the step-by-step instructions provided by the DevTV and My First Revit Plugin video tutorials:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

That will explain all you need, including the answer to your question.

 

 

Once you have gotten your feet wet and are a little bit less green behind the ears by your own effort, it might become time for you to ask others for help with your further progress.

 

Good luck and have fun!

 

Cheers,

 

Jeremy



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

Message 6 of 10

Anonymous
Not applicable

I tried using elment.Category.Id, and also element.Category.Name, but somehow I am getting null for element.Category.

 

Now, if I do

ElementFilter familyCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Windows);
ICollection<Element> elements = new FilteredElementCollector(doc).WherePasses(familyCategoryFilter).ToElements();

 

then, it returns me 19 windows elements. So, I am sure that there are elements with their BuiltInCategory defined as windows, and doors.

 

My main goal is to get all the BuiltInCategories/Families that are in the view. 

I am getting a list of all Elements in the scene by below code.

FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
ICollection<Element> elements = collector.OfClass(typeof(Family)).ToElements();

 

So, how can I get a unique list of all Families in the scene from the list of Elements. Or is there any other method to get a list of families?

0 Likes
Message 7 of 10

y.tselikovskiy
Explorer
Explorer

(BuiltInCategory)element.Category.Id.IntegerValue

Message 8 of 10

greg7KTAR
Contributor
Contributor

Correct me if I'm wrong, but it seems that what the questioner is after is a string, like OST_DuctCurves, or OST_Conduit

not an integer value, and not an Id (which in debug appears to be an Id as expected meaning an integer value - and in debug, that string is not further down the chain of the Element.Category part. This string would need to come after first getting a result in a BuiltInCategory enumeration. So how is it that this is listed as solved by Jeremy?

Message 9 of 10

greg7KTAR
Contributor
Contributor

I believe this is the complete code, if you need the user to select the element, otherwise selectionElement would come from a loop through the elements.

 

// Ask user to select one item.
var selectionReference = uidoc.Selection.PickObject(ObjectType.Element, "Pick an element (family part).");
var selectionElement = doc.GetElement(selectionReference);


Category category = selectionElement.Category;
BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue;

Message 10 of 10

jeremy_tammik
Alumni
Alumni

Unfortunately, the Category property is often (or mostly) not implemented in the Family class:

 

https://thebuildingcoder.typepad.com/blog/2017/01/family-category-and-two-energy-model-types.html#2

  

If you have a list of elements and wish to create a list of the families they represent, the easiest way would be to query each family instance for its symbol and the symbol for its family definition.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes