Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
thiru2jack
2121 Views, 3 Replies

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

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;
        }
    }
}
3 REPLIES 3
Message 2 of 4
sragan
in reply to: thiru2jack

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.

 

Message 3 of 4
mhannonQ65N2
in reply to: thiru2jack

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);
Message 4 of 4
thiru2jack
in reply to: mhannonQ65N2

@mhannonQ65N2 

can i know What is e in your code?

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

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report