Argument 1: cannot convert from 'System.Collections.Generic.IList<Autodesk.Revit.D.ElementId>' to 'Autodesk.Revit.DB.ElementId' (CS1503)

Argument 1: cannot convert from 'System.Collections.Generic.IList<Autodesk.Revit.D.ElementId>' to 'Autodesk.Revit.DB.ElementId' (CS1503)

T52K-BIB
Enthusiast Enthusiast
2,577 Views
3 Replies
Message 1 of 4

Argument 1: cannot convert from 'System.Collections.Generic.IList<Autodesk.Revit.D.ElementId>' to 'Autodesk.Revit.DB.ElementId' (CS1503)

T52K-BIB
Enthusiast
Enthusiast

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;
        }
    }
}
0 Likes
Accepted solutions (1)
2,578 Views
3 Replies
Replies (3)
Message 2 of 4

sragan
Collaborator
Collaborator

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.

 

0 Likes
Message 3 of 4

mhannonQ65N2
Collaborator
Collaborator
Accepted solution

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);
0 Likes
Message 4 of 4

T52K-BIB
Enthusiast
Enthusiast

@mhannonQ65N2 

can i know What is e in your code?

Where(e => e.Name == name).Select(e => e.Id).

 

0 Likes