I would like, for learning purposes, to know how I can select a specific element type.
For example:
Coletor FilteredElementCollector = novo FilteredElementCollector ( doc );
coletor.OfCategory ( BuiltInCategory .OST_Doors ); coletor.OfClass ( typeof ( FamilySymbol ) );
This command returns me all types of doors that belong to the OST_Doors category. I want to know if there is a way for me to select a specific port within that category.
Hi
If you want only one element, just get the element by id. If you want to filter by value, then you can do it with a simple loop.
You can try this sample code below. I have not tried it myself, but I think this is what you are looking for
FilteredElementCollector coletor = new FilteredElementCollector(doc);
coletor.OfClass(typeof(FamilySymbol));
coletor.OfCategory(BuiltInCategory.OST_Doors);
doors = coletor.ToElements();
if (0 == doors.Count)
{
throw new InvalidOperationException("There is no doors of the family.");
}
foreach (Element element in doors)
{
//write your code here for the element
}
I'm not sure if I understand your code, but I want one that returns a specific type of element, for example: "Generic - 90mm Brick" which is a type of element within the OST_Walls category. I want to pergar this one to create her or something like that.
ok that is not the initial question 🙂
if you want to filter by type of wall, first get the collector for wall instance (make sure there is no ElementType, but only instance). Then filter with a loop for wall with the same name string as the one you like.
Sorry, I think I expressed myself badly then. How would the code look? I'm noob in revit API, as in programming.
I was basically thinking about this logic, but I still don't know how to apply it
I am not sure I understand your question but if I did, you can try any of the examples below:
Example 1
View myActiveView = doc.ActiveView;
FilteredElementCollector wallfilter = new FilteredElementCollector(doc, myActiveView.Id);
List<Element> swwalls = wallfilter.OfCategory(BuiltInCategory.OST_Walls).ToList();
var elements = from element in wallfilter
where element.Name.Contains("Generic - 90mm Brick")
select element;
foreach (var element in elements)
{
TaskDialog.Show("Elements",element.Name);
}
Example 2
View myActiveView = doc.ActiveView;
FilteredElementCollector coletor = new FilteredElementCollector(doc, myActiveView.Id);
coletor.OfCategory(BuiltInCategory.OST_Walls);
var walls = coletor.ToElements();
if (0 == walls.Count)
{
throw new InvalidOperationException("There is no walls.");
}
foreach (Element element in walls)
{
//write your code here for the element
if(element.Name.Contains("Generic - 90mm Brick")){
TaskDialog.Show("Element", element.Name);
}
}
Use the Of category filter to select a specific family category, and .WhereElementIsElementType() to search among types "Sympols" only, finally the .Where(e=> e.Name.ToLower().Contains("0915")) to filter by name and replace "0915" by your desired name in lower case. @ferreirasou_gabriell
FamilySymbol FilterDoors(Document doc)
{
var myDoorsCollector = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Doors)
.WhereElementIsElementType()
.Where(e=> e.Name.ToLower().Contains("0915"))
.First() as FamilySymbol;
return myDoorsCollector;
}
Can't find what you're looking for? Ask the community or share your knowledge.