Community
hi everyone,
how can I solve this error please help me.
namespace RevitAddin3
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
//get input from form
Form1 form = new Form1(commandData);
form.ShowDialog();
string name = form.rnumber;
// get Room Element
RoomFilter filter = new RoomFilter();
FilteredElementCollector collector = new FilteredElementCollector(doc);
IList<Element> rooms = collector.WherePasses(filter).ToElements();
// Get the active view of the current document.
Autodesk.Revit.DB.View view = doc.ActiveView;
if (view is Autodesk.Revit.DB.ViewPlan)
{
foreach (Element e in rooms)
{
if (name == e.Name)
{
uidoc.Selection.SetElementIds(e.Id);
}
}
}
else
{
TaskDialog.Show("View", "Please make Sure Plan View");
return Result.Failed;
}
return Result.Succeeded;
}
}
}
Solved! Go to Solution.
Solved by mhannonQ65N2. Go to Solution.
I believe SetElementIds expects a collection of element id's. You are trying to set it to a single ID.
Put your ID in a collection like ICollection<ElementId> and use that in the SetElementId's line.
You need to pass a list of element ids not a single ElementId.
IList<ElementId> ids = rooms.Where(e => e.Name == name).Select(e => e.Id).ToList();
uidoc.Selection.SetElementIds(ids);
Can't find what you're looking for? Ask the community or share your knowledge.