Hi @huynguyen96str
You have to use FilteredElementCollector. Kindly check the below code snippet for additional reference
public void FilterRebarAndSetSelection(UIDocument uidoc)
{
// Get the Revit Document
Document doc = uidoc.Document;
// Create a FilteredElementCollector to collect all Rebar elements
FilteredElementCollector collector = new FilteredElementCollector(doc);
// Filter only Rebar elements
ICollection<Element> rebarElements = collector
.OfClass(typeof(Rebar))
.ToElements();
// Convert the rebar elements to a list of ElementIds
List<ElementId> rebarElementIds = rebarElements.Select(e => e.Id).ToList();
// Set the current selection to the Rebar elements
uidoc.Selection.SetElementIds(rebarElementIds);
}
call the method inside the Execute Function.
Hope this will helps 🙂