BIM secondary development of beginners for the first time to write filter, select the wall instance, compile no problem, but run in Revit without any reaction, consult you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The code wants to filter and select wall instances in Revit. The following is the code part:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
namespace Element filter
{
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
FilteredElementCollector wallTypeCollector1 = new FilteredElementCollector(doc);
ElementFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
wallTypeCollector1.OfClass(typeof(Wall)).WherePasses(filter);
IList<ElementId> elId = new List<ElementId>();
int im = 0;
foreach (Element el in wallTypeCollector1)
{
elId.Add(el.Id);
im = im + 1;
}
uidoc.Selection.SetElementIds(elId);
return Result.Succeeded;
}
}
}