Message 1 of 10

Not applicable
02-01-2018
09:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
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.
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_...
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
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?
(BuiltInCategory)element.Category.Id.IntegerValue
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?
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;
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.