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!

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!

Anonymous
Not applicable
216 Views
1 Reply
Message 1 of 2

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!

Anonymous
Not applicable

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;

}
}
}

0 Likes
217 Views
1 Reply
Reply (1)
Message 2 of 2

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

Your code looks fine.

//

FilteredElementCollector wallTypeCollector1 = new FilteredElementCollector(doc);
ElementFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
wallTypeCollector1.WherePasses(filter);
IList<ElementId> eids = wallTypeCollector1.ToElementIds() as IList<ElementId>;
uidoc.Selection.SetElementIds(eids);

//

Could you please explain what problem you are facing?

First, I would very strongly recommend that you work through the step-by-step instructions provided in the Revit My first plugin

https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/simplecontent/content/lesson-1-the-basic-plug.html 

 

 

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes