title: Modify selection to first element by Selection.SetElementIds
body: <p>I'm having trouble writing a script that lets med select the first element in my selection. This is useful for me because i select my correct Air Terminal from a schedule (where I can see the similar air-flow which I want to use) and use the command Create Similar from the selection. The trouble is that this command does not work when multiple elements are selected. Therefore, I want the first object from the list.
  This is the code which I'm trying:</p>
  
  <pre><code>from Autodesk.Revit.UI.Selection.Selection import SetElementIds
  from System.Collections.Generic import List
  
  uidoc = __revit__.ActiveUIDocument
  doc = __revit__.ActiveUIDocument.Document
  selection = [ doc.GetElement( elId ) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds() ]
  sel=[]
  for i in selection:
      sel.append(i.Id)
  uidoc.Selection.SetElementIds(List[ElementId](sel[0]))
  </code></pre>
  
  <p>That will return the following error message:</p>
  
  <p><a href="https://i.stack.imgur.com/Or6Qs.png" rel="nofollow noreferrer">Exception : Microsoft.Scripting.ArgumentTypeException: expected int, got ElementId</a>
  OK, then I'll try to replace</p>
  
  <pre><code>uidoc.Selection.SetElementIds(List[ElementId](sel[0]))
  </code></pre>
  
  <p>with</p>
  
  <pre><code>uidoc.Selection.SetElementIds(List[ElementId](sel[0].IntegerValue))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/0nR8z.png" rel="nofollow noreferrer">This seems to work, but selection is not modified</a></p>
  
  <p>I am just starting to write RPS-scripts, but I'm hoping someone will show me what am I doing wrong here even if it is very obvious.</p>
  
  <p>Thank you.
  Kyrre</p>
  
  <p>EDIT:
  Thank you Jeremy, for solving this for me! The trick was to generate a List, not a python list. .Add method is what I did not get.</p>
  
  <p>Final code if someone is interested:</p>
  
  <pre><code>from Autodesk.Revit.UI.Selection.Selection import SetElementIds
  from System.Collections.Generic import List
  from Autodesk.Revit.DB import ElementId
  uidoc = __revit__.ActiveUIDocument
  doc = __revit__.ActiveUIDocument.Document
  selection = [ doc.GetElement( elId ) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds() ]
  sel=[]
  for i in selection:
      sel.append(i.Id)
  ids=List[ElementId](1)
  ids.Add(sel[0]) 
  uidoc.Selection.SetElementIds(ids)
  </code></pre>